Type Checker: Add size check for fixed point types.

This commit is contained in:
Alexander Arlt 2021-08-04 14:32:37 -05:00
parent 0e6a0769fa
commit cbc2acf83e
2 changed files with 22 additions and 0 deletions

View File

@ -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;
}

View 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.