mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Type after shift should be type of left operand.
This commit is contained in:
parent
b8b4f5e9f9
commit
2df60bec92
@ -340,6 +340,28 @@ TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointe
|
|||||||
_other->category() != category()
|
_other->category() != category()
|
||||||
)
|
)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
|
if (Token::isShiftOp(_operator))
|
||||||
|
{
|
||||||
|
// Disable >>> here.
|
||||||
|
if (_operator == Token::SHR)
|
||||||
|
return TypePointer();
|
||||||
|
|
||||||
|
// Shifts are not symmetric with respect to the type
|
||||||
|
if (isAddress())
|
||||||
|
return TypePointer();
|
||||||
|
if (IntegerType const* otherInt = dynamic_cast<decltype(otherInt)>(_other.get()))
|
||||||
|
{
|
||||||
|
if (!otherInt->isAddress())
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
else if (RationalNumberType const* otherRat = dynamic_cast<decltype(otherRat)>(_other.get()))
|
||||||
|
{
|
||||||
|
if (!otherRat->isFractional())
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
return TypePointer();
|
||||||
|
}
|
||||||
|
|
||||||
auto commonType = Type::commonType(shared_from_this(), _other); //might be a integer or fixed point
|
auto commonType = Type::commonType(shared_from_this(), _other); //might be a integer or fixed point
|
||||||
if (!commonType)
|
if (!commonType)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
@ -347,11 +369,6 @@ TypePointer IntegerType::binaryOperatorResult(Token::Value _operator, TypePointe
|
|||||||
// All integer types can be compared
|
// All integer types can be compared
|
||||||
if (Token::isCompareOp(_operator))
|
if (Token::isCompareOp(_operator))
|
||||||
return commonType;
|
return commonType;
|
||||||
// Disable >>> here.
|
|
||||||
if (_operator == Token::SHR)
|
|
||||||
return TypePointer();
|
|
||||||
if (Token::isShiftOp(_operator) && !isAddress()) // && !_other->isAddress())
|
|
||||||
return shared_from_this();
|
|
||||||
if (Token::isBooleanOp(_operator))
|
if (Token::isBooleanOp(_operator))
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
|
if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
|
||||||
@ -959,6 +976,26 @@ TypePointer FixedBytesType::unaryOperatorResult(Token::Value _operator) const
|
|||||||
|
|
||||||
TypePointer FixedBytesType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const
|
TypePointer FixedBytesType::binaryOperatorResult(Token::Value _operator, TypePointer const& _other) const
|
||||||
{
|
{
|
||||||
|
if (Token::isShiftOp(_operator))
|
||||||
|
{
|
||||||
|
// Disable >>> here.
|
||||||
|
if (_operator == Token::SHR)
|
||||||
|
return TypePointer();
|
||||||
|
|
||||||
|
// Shifts are not symmetric with respect to the type
|
||||||
|
if (IntegerType const* otherInt = dynamic_cast<decltype(otherInt)>(_other.get()))
|
||||||
|
{
|
||||||
|
if (!otherInt->isAddress())
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
else if (RationalNumberType const* otherRat = dynamic_cast<decltype(otherRat)>(_other.get()))
|
||||||
|
{
|
||||||
|
if (!otherRat->isFractional())
|
||||||
|
return shared_from_this();
|
||||||
|
}
|
||||||
|
return TypePointer();
|
||||||
|
}
|
||||||
|
|
||||||
auto commonType = dynamic_pointer_cast<FixedBytesType const>(Type::commonType(shared_from_this(), _other));
|
auto commonType = dynamic_pointer_cast<FixedBytesType const>(Type::commonType(shared_from_this(), _other));
|
||||||
if (!commonType)
|
if (!commonType)
|
||||||
return TypePointer();
|
return TypePointer();
|
||||||
|
@ -8505,6 +8505,21 @@ BOOST_AUTO_TEST_CASE(shift_left_uint8)
|
|||||||
BOOST_CHECK(callContractFunction("f(uint8,uint8)", u256(0x66), u256(8)) == encodeArgs(u256(0)));
|
BOOST_CHECK(callContractFunction("f(uint8,uint8)", u256(0x66), u256(8)) == encodeArgs(u256(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(shift_left_larger_type)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract C {
|
||||||
|
function f() returns (int8) {
|
||||||
|
uint8 x = 255;
|
||||||
|
int8 y = 1;
|
||||||
|
return a << b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode, 0, "C");
|
||||||
|
BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(1) << 255));
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(shift_left_assignment)
|
BOOST_AUTO_TEST_CASE(shift_left_assignment)
|
||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user