mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Type Checker: Add size check for fixed point types.
This commit is contained in:
parent
0e6a0769fa
commit
cbc2acf83e
@ -608,6 +608,20 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
|
||||
}
|
||||
}
|
||||
|
||||
auto fixedPoint = dynamic_cast<FixedPointType const*>(_variable.annotation().type);
|
||||
if (fixedPoint)
|
||||
{
|
||||
bigint fixedPointTypeSize = boost::multiprecision::pow(bigint(2), fixedPoint->numBits());
|
||||
bigint digitSize = boost::multiprecision::pow(bigint(10), fixedPoint->fractionalDigits());
|
||||
if (fixedPointTypeSize <= digitSize)
|
||||
m_errorReporter.typeError(
|
||||
5108_error,
|
||||
_variable.location(),
|
||||
"Invalid fixed point type " + fixedPoint->toString(true) + ": 10^"
|
||||
+ std::to_string(fixedPoint->fractionalDigits()) + " does not fit in 2^"
|
||||
+ std::to_string(fixedPoint->numBits()) + " bits."
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
8
test/libsolidity/syntaxTests/fixed_point/type_size.sol
Normal file
8
test/libsolidity/syntaxTests/fixed_point/type_size.sol
Normal file
@ -0,0 +1,8 @@
|
||||
contract A
|
||||
{
|
||||
function s128x18() public pure returns (ufixed16x16 x) {
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError 5108: (57-70): Invalid fixed point type ufixed16x16: 10^16 does not fit in 2^16 bits.
|
Loading…
Reference in New Issue
Block a user