mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adds more detailed type errors and tests.
This commit is contained in:
parent
b2afb8cdda
commit
e2395a3dcf
@ -513,7 +513,7 @@ TypeResult AddressType::unaryOperatorResult(Token _operator) const
|
||||
TypeResult AddressType::binaryOperatorResult(Token _operator, TypePointer const& _other) const
|
||||
{
|
||||
if (!TokenTraits::isCompareOp(_operator))
|
||||
return TypeResult{"Addresses can only be compared"};
|
||||
return TypeResult{"Arithmetic operations on addresses are not supported. Convert to integer first before using them."};
|
||||
|
||||
return Type::commonType(shared_from_this(), _other);
|
||||
}
|
||||
@ -678,7 +678,7 @@ TypeResult IntegerType::binaryOperatorResult(Token _operator, TypePointer const&
|
||||
if (auto intType = dynamic_pointer_cast<IntegerType const>(commonType))
|
||||
{
|
||||
if (Token::Exp == _operator && intType->isSigned())
|
||||
return TypeResult{"Signed exponentiation is not allowed"};
|
||||
return TypeResult{"Exponentiation is not allowed for signed integer types."};
|
||||
}
|
||||
else if (auto fixType = dynamic_pointer_cast<FixedPointType const>(commonType))
|
||||
if (Token::Exp == _operator)
|
||||
@ -1127,7 +1127,7 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, TypePointer
|
||||
uint32_t absExp = bigint(abs(exp)).convert_to<uint32_t>();
|
||||
|
||||
if (!fitsPrecisionExp(abs(m_value.numerator()), absExp) || !fitsPrecisionExp(abs(m_value.denominator()), absExp))
|
||||
return TypeResult{"Precision is limited to 4096 bits"};
|
||||
return TypeResult{"Precision of rational constants is limited to 4096 bits."};
|
||||
|
||||
static auto const optimizedPow = [](bigint const& _base, uint32_t _exponent) -> bigint {
|
||||
if (_base == 1)
|
||||
@ -1208,7 +1208,7 @@ TypeResult RationalNumberType::binaryOperatorResult(Token _operator, TypePointer
|
||||
|
||||
// verify that numerator and denominator fit into 4096 bit after every operation
|
||||
if (value.numerator() != 0 && max(mostSignificantBit(abs(value.numerator())), mostSignificantBit(abs(value.denominator()))) > 4096)
|
||||
return TypeResult{"Precision is limited to 4096 bits"};
|
||||
return TypeResult{"Precision of rational constants is limited to 4096 bits."};
|
||||
|
||||
return TypeResult(make_shared<RationalNumberType>(value));
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
contract test { function() external { int x = -3; int y = -4; x ** y; } }
|
||||
contract test {
|
||||
function f() public { int x = 3; int y = 4; x ** y; }
|
||||
function g() public { int16 x = 3; uint8 y = 4; x ** y; }
|
||||
function h() public { uint8 x = 3; int16 y = 4; x ** y; }
|
||||
}
|
||||
// ----
|
||||
// TypeError: (62-68): Operator ** not compatible with types int256 and int256. Signed exponentiation is not allowed
|
||||
// TypeError: (64-70): Operator ** not compatible with types int256 and int256. Exponentiation is not allowed for signed integer types.
|
||||
// TypeError: (126-132): Operator ** not compatible with types int16 and uint8. Exponentiation is not allowed for signed integer types.
|
||||
// TypeError: (188-194): Operator ** not compatible with types uint8 and int16. Exponentiation is not allowed for signed integer types.
|
||||
|
@ -9,7 +9,7 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (85-108): Operator + not compatible with types address payable and address payable. Addresses can only be compared
|
||||
// TypeError: (122-145): Operator - not compatible with types address payable and address payable. Addresses can only be compared
|
||||
// TypeError: (159-182): Operator * not compatible with types address payable and address payable. Addresses can only be compared
|
||||
// TypeError: (196-219): Operator / not compatible with types address payable and address payable. Addresses can only be compared
|
||||
// TypeError: (85-108): Operator + not compatible with types address payable and address payable. Arithmetic operations on addresses are not supported. Convert to integer first before using them.
|
||||
// TypeError: (122-145): Operator - not compatible with types address payable and address payable. Arithmetic operations on addresses are not supported. Convert to integer first before using them.
|
||||
// TypeError: (159-182): Operator * not compatible with types address payable and address payable. Arithmetic operations on addresses are not supported. Convert to integer first before using them.
|
||||
// TypeError: (196-219): Operator / not compatible with types address payable and address payable. Arithmetic operations on addresses are not supported. Convert to integer first before using them.
|
||||
|
@ -5,5 +5,5 @@ contract c {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-92): Operator / not compatible with types rational_const 1 / 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168. Precision is limited to 4096 bits
|
||||
// TypeError: (71-92): Operator / not compatible with types rational_const 1 / 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (71-92): Type rational_const 1 / 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256. Try converting to type ufixed8x80 or use an explicit conversion.
|
||||
|
@ -19,23 +19,23 @@ contract c {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-102): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4. Precision is limited to 4096 bits
|
||||
// TypeError: (71-102): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (71-102): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (116-148): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4. Precision is limited to 4096 bits
|
||||
// TypeError: (116-153): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4. Precision is limited to 4096 bits
|
||||
// TypeError: (116-148): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (116-153): Operator ** not compatible with types int_const 1797...(301 digits omitted)...7216 and int_const 4. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (116-153): Type int_const 1797...(301 digits omitted)...7216 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (167-203): Operator ** not compatible with types int_const 4 and int_const -179...(302 digits omitted)...7216
|
||||
// TypeError: (217-228): Operator ** not compatible with types int_const 2 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (242-254): Operator ** not compatible with types int_const -2 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (268-280): Operator ** not compatible with types int_const 2 and int_const -100...(1227 digits omitted)...0000
|
||||
// TypeError: (294-307): Operator ** not compatible with types int_const -2 and int_const -100...(1227 digits omitted)...0000
|
||||
// TypeError: (321-332): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2. Precision is limited to 4096 bits
|
||||
// TypeError: (321-332): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 2. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (321-332): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (346-358): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 2. Precision is limited to 4096 bits
|
||||
// TypeError: (346-358): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const 2. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (346-358): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (372-384): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -2. Precision is limited to 4096 bits
|
||||
// TypeError: (372-384): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const -2. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (372-384): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (398-411): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -2. Precision is limited to 4096 bits
|
||||
// TypeError: (398-411): Operator ** not compatible with types int_const -100...(1227 digits omitted)...0000 and int_const -2. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (398-411): Type int_const -100...(1227 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
// TypeError: (425-441): Operator ** not compatible with types int_const 1000...(1226 digits omitted)...0000 and int_const 1000...(1226 digits omitted)...0000
|
||||
// TypeError: (425-441): Type int_const 1000...(1226 digits omitted)...0000 is not implicitly convertible to expected type int256.
|
||||
|
@ -5,5 +5,5 @@ contract c {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (71-90): Operator * not compatible with types int_const 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168. Precision is limited to 4096 bits
|
||||
// TypeError: (71-90): Operator * not compatible with types int_const 5221...(1225 digits omitted)...5168 and int_const 5221...(1225 digits omitted)...5168. Precision of rational constants is limited to 4096 bits.
|
||||
// TypeError: (71-90): Type int_const 5221...(1225 digits omitted)...5168 is not implicitly convertible to expected type int256.
|
||||
|
Loading…
Reference in New Issue
Block a user