Disallow more than 77 fractional digits.

This commit is contained in:
chriseth 2021-08-19 17:04:58 +02:00
parent 96d50431bb
commit 3fe4b0b2c3
9 changed files with 15 additions and 15 deletions

View File

@ -62,7 +62,7 @@ The following elementary types exist:
- ``bool``: equivalent to ``uint8`` restricted to the values 0 and 1. For computing the function selector, ``bool`` is used.
- ``fixed<M>x<N>``: signed fixed-point decimal number of ``M`` bits, ``8 <= M <= 256``,
``M % 8 == 0``, and ``0 < N <= 80``, which denotes the value ``v`` as ``v / (10 ** N)``.
``M % 8 == 0``, and ``0 < N <= 77``, which denotes the value ``v`` as ``v / (10 ** N)``.
- ``ufixed<M>x<N>``: unsigned variant of ``fixed<M>x<N>``.

View File

@ -213,7 +213,7 @@ tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(string const& _
int n = parseSize(positionX + 1, _literal.end());
if (
8 <= m && m <= 256 && m % 8 == 0 &&
0 <= n && n <= 80
0 <= n && n <= 77
) {
if (keyword == Token::UFixed)
return make_tuple(Token::UFixedMxN, m, n);

View File

@ -670,7 +670,7 @@ FixedPointType::FixedPointType(unsigned _totalBits, unsigned _fractionalDigits,
m_totalBits(_totalBits), m_fractionalDigits(_fractionalDigits), m_modifier(_modifier)
{
solAssert(
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 && m_fractionalDigits <= 80,
8 <= m_totalBits && m_totalBits <= 256 && m_totalBits % 8 == 0 && m_fractionalDigits <= 77,
"Invalid bit number(s) for fixed type: " +
util::toString(_totalBits) + "x" + util::toString(_fractionalDigits)
);

View File

@ -1,7 +1,7 @@
contract test {
function f() public {
ufixed256x18 a = ufixed256x18(1/3); a;
ufixed248x18 b = ufixed248x18(1/3); b;
ufixed256x77 a = ufixed256x77(1/3); a;
ufixed248x77 b = ufixed248x77(1/3); b;
ufixed8x1 c = ufixed8x1(1/3); c;
}
}

View File

@ -9,9 +9,9 @@ contract C {
bytes payable h;
bytes32 payable i;
fixed payable j;
fixed80x80 payable k;
fixed80x77 payable k;
ufixed payable l;
ufixed80x80 payable m;
ufixed80x77 payable m;
}
// ----
// ParserError 9106: (22-29): State mutability can only be specified for address types.

View File

@ -9,9 +9,9 @@ contract C {
function h(bytes payable) public pure {}
function i(bytes32 payable) public pure {}
function j(fixed payable) public pure {}
function k(fixed80x80 payable) public pure {}
function k(fixed80x77 payable) public pure {}
function l(ufixed payable) public pure {}
function m(ufixed80x80 payable) public pure {}
function m(ufixed80x77 payable) public pure {}
}
// ----
// ParserError 9106: (33-40): State mutability can only be specified for address types.

View File

@ -10,9 +10,9 @@ contract C {
bytes payable h;
bytes32 payable i;
fixed payable j;
fixed80x80 payable k;
fixed80x77 payable k;
ufixed payable l;
ufixed80x80 payable m;
ufixed80x77 payable m;
}
}
// ----

View File

@ -9,9 +9,9 @@ contract C {
function h() public pure returns (bytes payable) {}
function i() public pure returns (bytes32 payable) {}
function j() public pure returns (fixed payable) {}
function k() public pure returns (fixed80x80 payable) {}
function k() public pure returns (fixed80x77 payable) {}
function l() public pure returns (ufixed payable) {}
function m() public pure returns (ufixed80x80 payable) {}
function m() public pure returns (ufixed80x77 payable) {}
}
// ----
// ParserError 9106: (56-63): State mutability can only be specified for address types.

View File

@ -1,5 +1,5 @@
contract C {
fixed8x80 a = -1e-100;
fixed8x77 a = -1e-100;
}
// ----
// TypeError 7407: (29-36): Type rational_const -1 / 1000...(93 digits omitted)...0000 is not implicitly convertible to expected type fixed8x80. Conversion incurs precision loss. Use an explicit conversion instead.
// TypeError 7407: (29-36): Type rational_const -1 / 1000...(93 digits omitted)...0000 is not implicitly convertible to expected type fixed8x77. Conversion incurs precision loss. Use an explicit conversion instead.