mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Warn about literal constant base in exponentiation.
This commit is contained in:
parent
774cdb1135
commit
1324ebc4bf
@ -6,6 +6,7 @@ Features:
|
|||||||
* Code generator: Support ``revert()`` to abort with rolling back, but not consuming all gas.
|
* Code generator: Support ``revert()`` to abort with rolling back, but not consuming all gas.
|
||||||
* Inline assembly: Support ``revert`` (EIP140) as an opcode.
|
* Inline assembly: Support ``revert`` (EIP140) as an opcode.
|
||||||
* Type system: Support explicit conversion of external function to address.
|
* Type system: Support explicit conversion of external function to address.
|
||||||
|
* Type system: Warn if base of exponentiation is literal (result type might be unexpected).
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``).
|
* Commandline interface: Always escape filenames (replace ``/``, ``:`` and ``.`` with ``_``).
|
||||||
|
@ -1092,6 +1092,26 @@ void TypeChecker::endVisit(BinaryOperation const& _operation)
|
|||||||
Token::isCompareOp(_operation.getOperator()) ?
|
Token::isCompareOp(_operation.getOperator()) ?
|
||||||
make_shared<BoolType>() :
|
make_shared<BoolType>() :
|
||||||
commonType;
|
commonType;
|
||||||
|
if (_operation.getOperator() == Token::Exp)
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
leftType->category() == Type::Category::RationalNumber &&
|
||||||
|
rightType->category() != Type::Category::RationalNumber
|
||||||
|
)
|
||||||
|
if ((
|
||||||
|
commonType->category() == Type::Category::Integer &&
|
||||||
|
dynamic_cast<IntegerType const&>(*commonType).numBits() != 256
|
||||||
|
) || (
|
||||||
|
commonType->category() == Type::Category::FixedPoint &&
|
||||||
|
dynamic_cast<FixedPointType const&>(*commonType).numBits() != 256
|
||||||
|
))
|
||||||
|
warning(
|
||||||
|
_operation.location(),
|
||||||
|
"Result of exponentiation has type " + commonType->toString() + " and thus "
|
||||||
|
"might overflow. Silence this warning by converting the literal to the "
|
||||||
|
"expected type."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TypeChecker::visit(FunctionCall const& _functionCall)
|
bool TypeChecker::visit(FunctionCall const& _functionCall)
|
||||||
|
Loading…
Reference in New Issue
Block a user