User-defined literal suffixes: Tests

This commit is contained in:
Kamil Śliwak
2023-05-17 16:55:14 +02:00
parent 0e5c7d81c6
commit 976f014c12
206 changed files with 3644 additions and 0 deletions
@@ -0,0 +1,13 @@
function suffix(uint) pure suffix returns (uint) {
revert();
}
contract C {
function f() public pure {
1 suffix;
uint a = 0;
a;
}
}
// ----
// Warning 5740: (138-159): Unreachable code.
@@ -0,0 +1,17 @@
==== Source: A.sol ====
function suffix(uint) pure suffix returns (uint) {
revert();
}
==== Source: B.sol ====
import "A.sol" as A;
contract C {
function f() public pure {
1 A.suffix;
uint a = 0;
a;
}
}
// ----
// Warning 5740: (B.sol:94-115): Unreachable code.
@@ -0,0 +1,11 @@
function suffix(uint) pure suffix returns (uint) {}
library L {
function add(uint, uint) internal pure returns (uint) {}
}
contract C {
using L for *;
uint x = (1000 suffix).add(1);
}
@@ -0,0 +1,7 @@
function suffix(uint) pure suffix returns (function () external) {}
contract C {
address x = 1000 suffix.address;
}
// ----
// ParserError 2314: (110-117): Expected identifier but got 'address'
@@ -0,0 +1,13 @@
function suffix(uint) pure suffix returns (uint) {}
library L {
function add(uint, uint) internal pure returns (uint) {}
}
contract C {
using L for *;
uint x = 1000 suffix.add(1);
}
// ----
// TypeError 9582: (180-190): Member "add" not found or not visible after argument-dependent lookup in function (uint256) pure returns (uint256).
@@ -0,0 +1,7 @@
function suffix(uint) pure suffix returns (uint) { return 1; }
contract C {
uint x = 2 ether suffix;
}
// ----
// ParserError 2314: (98-104): Expected ';' but got identifier
@@ -0,0 +1,7 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
uint x = 1.618suffix;
}
// ----
// ParserError 8936: (92-97): Identifier-start is not allowed at end of a number.
@@ -0,0 +1,7 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
uint x = 0x1000suffix;
}
// ----
// ParserError 8936: (92-98): Identifier-start is not allowed at end of a number.
@@ -0,0 +1,7 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
contract C {
uint x = 1000 suffix 1000 suffix;
}
// ----
// ParserError 2314: (112-116): Expected ';' but got 'Number'
@@ -0,0 +1,7 @@
function suffix(uint) pure returns (uint) {}
contract C {
uint x = 1 suffx;
}
// ----
// DeclarationError 7576: (74-79): Undeclared identifier. Did you mean "suffix"?
@@ -0,0 +1,7 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
uint x = 1000.0e-5suffix;
}
// ----
// ParserError 8936: (92-101): Identifier-start is not allowed at end of a number.
@@ -0,0 +1,7 @@
function suffix(uint) pure suffix returns (function () external) {}
contract C {
bytes4 x = 1000 suffix.selector;
}
// ----
// TypeError 9582: (102-117): Member "selector" not found or not visible after argument-dependent lookup in function (uint256) pure returns (function () external).
@@ -0,0 +1,13 @@
function suffix(uint) pure suffix returns (string memory) {}
interface I {
function f() external payable;
}
contract C {
function f() public {
I(address(42)).f{value: 5 suffix, gas: 1 suffix}();
}
}
// ----
// TypeError 7407: (184-192): Type string memory is not implicitly convertible to expected type uint256.
// TypeError 7407: (199-207): Type string memory is not implicitly convertible to expected type uint256.
@@ -0,0 +1,7 @@
function suffix(string memory s) pure suffix returns (string memory) { return s; }
contract C {
uint x = "abcd" suffix "abcd";
}
// ----
// ParserError 2314: (124-130): Expected ';' but got 'StringLiteral'
@@ -0,0 +1,7 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
contract C {
uint x = suffix 1000;
}
// ----
// ParserError 2314: (107-111): Expected ';' but got 'Number'
@@ -0,0 +1,7 @@
function suffix(uint) pure suffix returns (uint) { return 1; }
contract C {
uint x = 8 suffix gwei;
}
// ----
// ParserError 2314: (99-103): Expected ';' but got 'gwei'
@@ -0,0 +1,9 @@
function suffix(string memory s) pure suffix returns (string memory) { return s; }
contract C {
function f() public pure {
delete "abc" suffix;
}
}
// ----
// TypeError 4247: (143-155): Expression has to be an lvalue.
@@ -0,0 +1,7 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
uint x = 1000suffix;
}
// ----
// ParserError 8936: (92-96): Identifier-start is not allowed at end of a number.
@@ -0,0 +1,7 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
contract C {
uint x = 1000 suffix{gas: 1};
}
// ----
// TypeError 2622: (100-119): Expected callable expression before call options.
@@ -0,0 +1,7 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
contract C {
uint x = 1000 suffix();
}
// ----
// TypeError 5704: (100-113): This expression is not callable.
@@ -0,0 +1,11 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
function f() pure public {
assembly ("memory-safe" suffix) {
pop(0)
}
}
}
// ----
// ParserError 2314: (142-148): Expected ')' but got identifier
@@ -0,0 +1,7 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
contract C {
int x = int(1000) suffix;
}
// ----
// ParserError 2314: (109-115): Expected ';' but got identifier
@@ -0,0 +1,7 @@
function suffix(uint a, uint b) pure suffix returns (uint) { return a + b; }
contract C {
uint x = 1000 1 suffix;
}
// ----
// ParserError 2314: (109-110): Expected ';' but got 'Number'
@@ -0,0 +1,9 @@
enum E {A, B, C}
function suffix(E) pure suffix returns (E) {}
contract C {
E e = E.A suffix;
}
// ----
// ParserError 2314: (92-98): Expected ';' but got identifier
@@ -0,0 +1,11 @@
function suffix(uint x) pure returns (uint) { return x; }
contract C {
error E();
function f() public {
revert E suffix;
}
}
// ----
// ParserError 2314: (131-137): Expected '(' but got identifier
@@ -0,0 +1,11 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
event E();
function f() public {
emit E suffix;
}
}
// ----
// ParserError 2314: (136-142): Expected '(' but got identifier
@@ -0,0 +1,61 @@
==== Source: A.sol ====
function uintSuffix(uint x) pure suffix returns (uint) {}
function int8Suffix(uint x) pure suffix returns (int8) {}
function addressSuffix(uint x) pure suffix returns (address) {}
function decimalSuffix(uint m, uint e) pure suffix returns (uint) {}
function stringSuffix(uint x) pure suffix returns (string memory) {}
function bytesSuffix(uint x) pure suffix returns (bytes memory) {}
==== Source: B.sol ====
import "A.sol" as A;
import "A.sol";
contract C {
uint[42 uintSuffix] a;
uint[42 int8Suffix] b;
uint[42 addressSuffix] c;
uint[42 decimalSuffix] d;
uint[42 stringSuffix] e;
uint[42 bytesSuffix] f;
uint[42 A.uintSuffix] a;
uint[42 A.int8Suffix] b;
uint[42 A.addressSuffix] c;
uint[42 A.decimalSuffix] d;
uint[42 A.stringSuffix] e;
uint[42 A.bytesSuffix] f;
}
contract D {
uint[uintSuffix(42)] a;
uint[int8Suffix(42)] b;
uint[addressSuffix(42)] c;
uint[decimalSuffix(42)] d;
uint[stringSuffix(42)] e;
uint[bytesSuffix(42)] f;
}
// ----
// DeclarationError 2333: (B.sol:227-250): Identifier already declared.
// DeclarationError 2333: (B.sol:256-279): Identifier already declared.
// DeclarationError 2333: (B.sol:285-311): Identifier already declared.
// DeclarationError 2333: (B.sol:317-343): Identifier already declared.
// DeclarationError 2333: (B.sol:349-374): Identifier already declared.
// DeclarationError 2333: (B.sol:380-404): Identifier already declared.
// TypeError 5462: (B.sol:60-73): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:87-100): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:114-130): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:144-160): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:174-189): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:203-217): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:232-247): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:261-276): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:290-308): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:322-340): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:354-371): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:385-401): Invalid array length, expected integer literal or constant expression. A suffixed literal is not a constant expression unless the suffix is a subdenomination.
// TypeError 5462: (B.sol:431-445): Invalid array length, expected integer literal or constant expression.
// TypeError 5462: (B.sol:459-473): Invalid array length, expected integer literal or constant expression.
// TypeError 5462: (B.sol:487-504): Invalid array length, expected integer literal or constant expression.
// TypeError 5462: (B.sol:518-535): Invalid array length, expected integer literal or constant expression.
// TypeError 5462: (B.sol:549-565): Invalid array length, expected integer literal or constant expression.
// TypeError 5462: (B.sol:579-594): Invalid array length, expected integer literal or constant expression.
@@ -0,0 +1,22 @@
function uintSuffix(uint x) pure suffix returns (uint) { return x; }
function int8Suffix(int8 x) pure suffix returns (int8) { return x; }
function addressSuffix(address x) pure suffix returns (address) { return x; }
function decimalSuffix(uint m, uint e) pure suffix returns (uint) { return m + e; }
function stringSuffix(string memory x) pure suffix returns (string memory) { return x; }
function bytesSuffix(bytes memory x) pure suffix returns (bytes memory) { return x; }
contract C {
uint constant a = 1 uintSuffix;
int8 constant b = 1 int8Suffix;
address constant c = 0x1234567890123456789012345678901234567890 addressSuffix;
uint constant d = 1.1 decimalSuffix;
string constant e = "a" stringSuffix;
bytes constant f = hex"abcd" bytesSuffix;
}
// ----
// TypeError 8349: (511-523): Initial value for constant variable has to be compile-time constant.
// TypeError 8349: (547-559): Initial value for constant variable has to be compile-time constant.
// TypeError 8349: (586-642): Initial value for constant variable has to be compile-time constant.
// TypeError 8349: (666-683): Initial value for constant variable has to be compile-time constant.
// TypeError 8349: (709-725): Initial value for constant variable has to be compile-time constant.
// TypeError 8349: (750-771): Initial value for constant variable has to be compile-time constant.
@@ -0,0 +1,8 @@
function suffix(string memory s, string memory) pure suffix returns (string memory) { return s; }
contract C {
string s = "abcd" "" suffix;
}
// ----
// TypeError 1587: (15-47): Literal suffix function has invalid parameter types. The mantissa parameter must be an integer. The exponent parameter must be an unsigned integer.
// TypeError 2505: (137-143): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
@@ -0,0 +1,5 @@
function x(uint v) pure suffix returns (uint) { return v; }
pragma solidity 1 x;
// ----
// ParserError 5333: (61-81): Source file requires different compiler version (current compiler is ....
@@ -0,0 +1,7 @@
function suffix(string memory) pure suffix returns (string memory) {}
contract C {
string s = "abcd" suffix "abcd" suffix;
}
// ----
// ParserError 2314: (113-119): Expected ';' but got 'StringLiteral'
@@ -0,0 +1,11 @@
struct S {
uint x;
}
function suffix(S memory) pure suffix returns (S memory) {}
contract C {
uint x = (S suffix);
}
// ----
// ParserError 2314: (116-122): Expected ',' but got identifier
@@ -0,0 +1,8 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
function metasuffix(function (uint) pure returns (uint) value) pure suffix returns (uint) { return value; }
contract C {
uint x = suffix metasuffix;
}
// ----
// ParserError 2314: (215-225): Expected ';' but got identifier
@@ -0,0 +1,7 @@
function suffix(uint value) pure suffix returns (uint) { return value; }
contract C {
uint x = 1000 suffix suffix;
}
// ----
// ParserError 2314: (112-118): Expected ';' but got identifier
@@ -0,0 +1,8 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
uint v = 42;
uint x = v suffix;
}
// ----
// ParserError 2314: (111-117): Expected ';' but got identifier
@@ -0,0 +1,11 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
function f() pure public {
assembly {
pop(0 suffix)
}
}
}
// ----
// ParserError 2314: (147-153): Expected ',' but got identifier
@@ -0,0 +1,7 @@
function suffix(uint) pure suffix returns (uint) {}
contract C {
uint x = 1000 suffix.value;
}
// ----
// TypeError 8820: (84-96): Member "value" is only available for payable functions.
@@ -0,0 +1,10 @@
function functionSuffix(uint) pure suffix returns (function () external) {}
function addressSuffix(uint) pure suffix returns (address payable) {}
function arraySuffix(uint) pure suffix returns (uint[] memory) {}
contract C {
bytes4 a = (1000 functionSuffix).selector;
address b = (1000 functionSuffix).address;
uint c = (1000 arraySuffix).length;
bool d = (1000 addressSuffix).send(1);
}
@@ -0,0 +1,7 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
function f() public pure {
suffix;
}
}
@@ -0,0 +1,5 @@
function suffix(uint) pure suffix returns (uint) {}
contract C {
function (uint) pure returns (uint) suffixPtr = suffix;
}
@@ -0,0 +1,5 @@
function suffix(uint x) pure suffix returns (uint) { return x; }
contract C {
uint immutable a = 1 suffix;
}
@@ -0,0 +1,76 @@
function stringSuffix(string memory) pure suffix returns (string memory) {}
function bytesSuffix(bytes memory) pure suffix returns (bytes memory) {}
contract C {
function testString() public pure {
"" "" stringSuffix;
'' '' stringSuffix;
"" "" "" "" stringSuffix;
""''""'' "" stringSuffix;
"abcd" "" stringSuffix;
"" "efgh" stringSuffix;
"abcd" "efgh" stringSuffix;
"abcd""efgh" stringSuffix;
"abcd" "efgh"stringSuffix;
"abcd""efgh"stringSuffix;
'abcd' '' stringSuffix;
'' 'efgh' stringSuffix;
'abcd' 'efgh' stringSuffix;
'abcd''efgh' stringSuffix;
'abcd' 'efgh'stringSuffix;
'abcd''efgh'stringSuffix;
"abcd" 'efgh' stringSuffix;
'abcd' "efgh" stringSuffix;
}
function testHex() public pure {
hex"" hex"" bytesSuffix;
hex'' hex'' bytesSuffix;
hex"" hex"" hex"" hex"" bytesSuffix;
hex""hex''hex""hex'' hex"" bytesSuffix;
hex"1122" hex"" bytesSuffix;
hex"" hex"3344" bytesSuffix;
hex"1122" hex"3344" bytesSuffix;
hex"1122"hex"3344" bytesSuffix;
hex"1122" hex"3344"bytesSuffix;
hex"1122"hex"3344"bytesSuffix;
hex'1122' hex'' bytesSuffix;
hex'' hex'3344' bytesSuffix;
hex'1122' hex'3344' bytesSuffix;
hex'1122'hex'3344' bytesSuffix;
hex'1122' hex'3344'bytesSuffix;
hex'1122'hex'3344'bytesSuffix;
hex"1122" hex'3344' bytesSuffix;
hex'1122' hex"3344" bytesSuffix;
}
function testUnicode() public pure {
unicode"" unicode"" stringSuffix;
unicode'' unicode'' stringSuffix;
unicode"" unicode"" unicode"" unicode"" stringSuffix;
unicode""unicode''unicode""unicode'' unicode"" stringSuffix;
unicode"😃" unicode"" stringSuffix;
unicode"" unicode"😃" stringSuffix;
unicode"😃" unicode"😃" stringSuffix;
unicode"😃"unicode"😃" stringSuffix;
unicode"😃" unicode"😃"stringSuffix;
unicode"😃"unicode"😃"stringSuffix;
unicode'😃' unicode'' stringSuffix;
unicode'' unicode'😃' stringSuffix;
unicode'😃' unicode'😃' stringSuffix;
unicode'😃'unicode'😃' stringSuffix;
unicode'😃' unicode'😃'stringSuffix;
unicode'😃'unicode'😃'stringSuffix;
unicode"😃" unicode'😃' stringSuffix;
unicode'😃' unicode"😃" stringSuffix;
}
}
@@ -0,0 +1,21 @@
function u8(uint m, uint8 e) pure suffix returns (uint) {}
function u16(uint m, uint16 e) pure suffix returns (uint) {}
function u256(uint m, uint e) pure suffix returns (uint) {}
contract C {
function min() public pure {
// We never use positive exponents so here it's just 0 and the whole number goes into mantissa
1.0e77 u8;
1.0e77 u16;
1.0e77 u256;
115792089237316195423570985008687907853269984665640564039457584007913129639935.0 u8; // 2**256 - 1
115792089237316195423570985008687907853269984665640564039457584007913129639935.0 u16; // 2**256 - 1
115792089237316195423570985008687907853269984665640564039457584007913129639935.0 u256; // 2**256 - 1
}
function max() public pure {
1e-255 u8;
1e-1233 u16;
}
}
@@ -0,0 +1,31 @@
function mi8eu8(int8 m, uint8 e) pure suffix returns (uint) {}
function u8(uint m, uint8 e) pure suffix returns (uint) {}
function u16(uint m, uint16 e) pure suffix returns (uint) {}
function u256(uint m, uint e) pure suffix returns (uint) {}
contract C {
function min() public pure {
// We never use positive exponents so here it's just 0 and the whole number goes into mantissa
1.0e78 u8;
1.0e78 u16;
1.0e78 u256;
115792089237316195423570985008687907853269984665640564039457584007913129639936 u8; // 2**256
115792089237316195423570985008687907853269984665640564039457584007913129639936 u16; // 2**256
115792089237316195423570985008687907853269984665640564039457584007913129639936 u256; // 2**256
}
function max() public pure {
1e-256 u8;
128e-256 mi8eu8;
}
}
// ----
// TypeError 8838: (401-407): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (420-426): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (440-446): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (462-540): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (565-643): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (668-746): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (811-817): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The exponent is out of range of type uint8.
// TypeError 8838: (830-838): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int8. The exponent is out of range of type uint8.
@@ -0,0 +1,10 @@
function fixedSuffix(fixed) pure suffix returns (uint) {}
function ufixedSuffix(ufixed) pure suffix returns (uint) {}
contract C {
uint u = 1.1 fixedSuffix;
uint uf = 1.1 ufixedSuffix;
}
// ----
// TypeError 2699: (21-26): Parameters of fixed-point types are not allowed in literal suffix functions. To support fractional literals the suffix function must accept two integer arguments (mantissa and exponent) that such literals can be decomposed into.
// TypeError 2699: (80-86): Parameters of fixed-point types are not allowed in literal suffix functions. To support fractional literals the suffix function must accept two integer arguments (mantissa and exponent) that such literals can be decomposed into.
@@ -0,0 +1,12 @@
function suffix(uint) pure suffix returns (uint) {}
contract C {
function suffix(uint) internal pure returns (uint) {}
function run() public pure returns (uint) {
return 1 suffix;
}
}
// ----
// Warning 2519: (70-123): This declaration shadows an existing declaration.
// TypeError 4438: (190-196): The literal suffix must be either a subdenomination or a file-level suffix function.
@@ -0,0 +1,26 @@
function s8(int8 x) pure suffix returns (uint) {}
function u8(uint8 x) pure suffix returns (uint) {}
function s16(int16 x) pure suffix returns (uint) {}
function u16(uint16 x) pure suffix returns (uint) {}
function s256(int x) pure suffix returns (uint) {}
function u256(uint x) pure suffix returns (uint) {}
contract C {
function min() public pure {
0 s8;
0 u8;
0 s16;
0 u16;
0 s256;
0 u256;
}
function max() public pure {
127 s8;
255 u8;
32767 s16;
65535 u16;
57896044618658097711785492504343953926634992332820282019728792003956564819967 s256; // 2**255 - 1
115792089237316195423570985008687907853269984665640564039457584007913129639935 u256; // 2**256 - 1
}
}
@@ -0,0 +1,24 @@
function s8(int8 x) pure suffix returns (uint) {}
function u8(uint8 x) pure suffix returns (uint) {}
function s16(int16 x) pure suffix returns (uint) {}
function u16(uint16 x) pure suffix returns (uint) {}
function s256(int x) pure suffix returns (uint) {}
function u256(uint x) pure suffix returns (uint) {}
contract C {
function max() public pure {
128 s8;
256 u8;
32768 s16;
65536 u16;
57896044618658097711785492504343953926634992332820282019728792003956564819968 s256; // 2**255
115792089237316195423570985008687907853269984665640564039457584007913129639936 u256; // 2**256
}
}
// ----
// TypeError 8838: (364-367): The number is out of range of type int8 accepted by the suffix function.
// TypeError 8838: (380-383): The number is out of range of type uint8 accepted by the suffix function.
// TypeError 8838: (396-401): The number is out of range of type int16 accepted by the suffix function.
// TypeError 8838: (415-420): The number is out of range of type uint16 accepted by the suffix function.
// TypeError 8838: (434-511): The number is out of range of type int256 accepted by the suffix function.
// TypeError 8838: (536-614): The number is out of range of type uint256 accepted by the suffix function.
@@ -0,0 +1,40 @@
function s8(int8 m, uint e) pure suffix returns (uint) {}
function u8(uint8 m, uint e) pure suffix returns (uint) {}
function s16(int16 m, uint e) pure suffix returns (uint) {}
function u16(uint16 m, uint e) pure suffix returns (uint) {}
function s256(int m, uint e) pure suffix returns (uint) {}
function u256(uint m, uint e) pure suffix returns (uint) {}
contract C {
function min() public pure {
0 s8;
0 u8;
0 s16;
0 u16;
0 s256;
0 u256;
0.0 s8;
0.0 u8;
0.0 s16;
0.0 u16;
0.0 s256;
0.0 u256;
}
function max() public pure {
127 s8;
255 u8;
32767 s16;
65535 u16;
57896044618658097711785492504343953926634992332820282019728792003956564819967 s256; // 2**255 - 1
115792089237316195423570985008687907853269984665640564039457584007913129639935 u256; // 2**256 - 1
1.27 s8;
2.55 u8;
3.2767 s16;
6.5535 u16;
5.7896044618658097711785492504343953926634992332820282019728792003956564819967 s256; // (2**255 - 1) * 10**-76
1.15792089237316195423570985008687907853269984665640564039457584007913129639935 u256; // (2**256 - 1) * 10**-77
}
}
@@ -0,0 +1,54 @@
function mi8eu8(int8 m, uint8 e) pure suffix returns (uint) {}
function s8(int8 m, uint e) pure suffix returns (uint) {}
function u8(uint8 m, uint e) pure suffix returns (uint) {}
function s16(int16 m, uint e) pure suffix returns (uint) {}
function u16(uint16 m, uint e) pure suffix returns (uint) {}
function s256(int m, uint e) pure suffix returns (uint) {}
function u256(uint m, uint e) pure suffix returns (uint) {}
contract C {
function max() public pure {
128 s8;
256 u8;
32768 s16;
65536 u16;
57896044618658097711785492504343953926634992332820282019728792003956564819968 s256; // 2**255
115792089237316195423570985008687907853269984665640564039457584007913129639936 u256; // 2**256
1.28 s8;
2.56 u8;
3.2768 s16;
6.5536 u16;
5.7896044618658097711785492504343953926634992332820282019728792003956564819968 s256; // 2**255 * 10**-76
1.15792089237316195423570985008687907853269984665640564039457584007913129639936 u256; // 2**256 * 10**-77
128_000 s8;
256_000 u8;
32768_000 s16;
65536_000 u16;
57896044618658097711785492504343953926634992332820282019728792003956564819968_000 s256; // 2**255 * 10**3
115792089237316195423570985008687907853269984665640564039457584007913129639936_000 u256; // 2**256 * 10**3
128e-256 mi8eu8;
}
}
// ----
// TypeError 8838: (475-478): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int8.
// TypeError 8838: (491-494): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type uint8.
// TypeError 8838: (507-512): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int16.
// TypeError 8838: (526-531): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type uint16.
// TypeError 8838: (545-622): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int256.
// TypeError 8838: (647-725): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (751-755): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int8.
// TypeError 8838: (768-772): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type uint8.
// TypeError 8838: (785-791): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int16.
// TypeError 8838: (805-811): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type uint16.
// TypeError 8838: (825-903): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int256.
// TypeError 8838: (938-1017): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (1053-1060): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int8.
// TypeError 8838: (1073-1080): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type uint8.
// TypeError 8838: (1093-1102): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int16.
// TypeError 8838: (1116-1125): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type uint16.
// TypeError 8838: (1139-1220): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (1253-1335): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of any possible suffix function. The mantissa is out of range of the largest supported integer type.
// TypeError 8838: (1369-1377): This number cannot be decomposed into a mantissa and decimal exponent that fit the range of parameters of the suffix function. The mantissa is out of range of type int8. The exponent is out of range of type uint8.
@@ -0,0 +1,22 @@
struct S { uint x; }
function uintUintSuffix(uint) pure suffix returns (uint, uint) {
return (1, 2);
}
function bytesStructContractSuffix(string memory s) pure suffix returns (bytes memory, S memory, C) {
return (bytes(s), S(42), C(address(0)));
}
contract C {
function f() public pure returns (uint, uint) {
return 1 uintUintSuffix;
}
function g() public pure returns (bytes memory, S memory, C) {
return "abcd" bytesStructContractSuffix;
}
}
// ----
// TypeError 7848: (72-84): Literal suffix functions must return exactly one value.
// TypeError 7848: (181-208): Literal suffix functions must return exactly one value.
@@ -0,0 +1,9 @@
function nullSuffix(uint) pure suffix {}
contract C {
function f() public pure {
return 1 nullSuffix;
}
}
// ----
// TypeError 7848: (38-38): Literal suffix functions must return exactly one value.
@@ -0,0 +1,5 @@
type B is bool;
function suffix(B x) pure suffix returns (B) {}
// ----
// TypeError 2998: (33-36): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
@@ -0,0 +1,11 @@
function suffix(uint) pure suffix returns (int) {}
function suffix(bool) pure suffix returns (bool) {}
function suffix(address) pure suffix returns (address) {}
function suffix(string memory) pure suffix returns (string memory) {}
contract C {
int a = 1 suffix;
bool b = true suffix;
address c = 0x1234567890123456789012345678901234567890 suffix;
string d = "a" suffix;
}
@@ -0,0 +1,9 @@
function suffix(address) pure suffix returns (address) {}
function suffix(address payable) pure suffix returns (address payable) {}
contract C {
address payable a = 0x1234567890123456789012345678901234567890 suffix;
}
// ----
// TypeError 2998: (74-89): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 7407: (170-219): Type address is not implicitly convertible to expected type address payable.
@@ -0,0 +1,19 @@
function s(uint) pure suffix returns (uint) {}
function s(string memory) pure returns (string memory) {}
function f(uint) pure returns (uint) {}
function f(string memory) pure suffix returns (string memory) {}
contract C {
function run() public pure {
1 s;
s(1);
//"a" s; // not allowed
s("a");
//1 f; // not allowed
f(1);
"a" f;
f("a");
}
}
@@ -0,0 +1,13 @@
function s(uint) pure suffix returns (uint) {}
function s(string memory) pure returns (string memory) {}
contract C {
function run() public pure {
1 s; // OK
s(1); // OK
"a" s; // not allowed
s("a"); // OK
}
}
// ----
// TypeError 9322: (208-209): No matching declaration found after argument-dependent lookup.
@@ -0,0 +1,8 @@
function uSuffix(uint8, uint) pure suffix returns (int8) {}
function uSuffix(uint16, uint) pure suffix returns (int16) {}
contract C {
int32 a = 115792089237316195423570985008687907853269984665640564039457584007913129639936 uSuffix; // 2**256
}
// ----
// TypeError 9322: (229-236): No matching declaration found after argument-dependent lookup.
@@ -0,0 +1,19 @@
function uSuffix(uint8, uint) pure suffix returns (uint) {}
function uSuffix(uint16, uint) pure suffix returns (int) {}
function iSuffix(int8, uint) pure suffix returns (uint) {}
function iSuffix(int16, uint) pure suffix returns (int) {}
function iuSuffix(uint8, uint) pure suffix returns (int) {}
function iuSuffix(int8, uint) pure suffix returns (uint) {}
contract C {
int a = 1.024 uSuffix;
int b = 1.024 iSuffix;
int c = -1.024 uSuffix;
int d = -1.024 iSuffix;
int e = 2.55 iuSuffix;
int f = -2.55 iuSuffix;
}
@@ -0,0 +1,8 @@
function iuSuffix(uint8, uint) pure suffix returns (int) {}
function iuSuffix(int8, uint) pure suffix returns (int) {}
contract C {
uint a = 1.27 iuSuffix;
}
// ----
// TypeError 4487: (151-159): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,8 @@
function uSuffix(uint8, uint) pure suffix returns (int) {}
function uSuffix(uint16, uint) pure suffix returns (int) {}
contract C {
uint a = 1.27 uSuffix;
}
// ----
// TypeError 4487: (151-158): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,31 @@
==== Source: A.sol ====
function s(uint, uint) pure suffix returns (uint) {}
function f(uint, uint) pure returns (uint) {}
==== Source: B.sol ====
import "A.sol";
function s(string memory) pure returns (string memory) {}
function f(string memory) pure suffix returns (string memory) {}
contract C {
function run() public pure {
1024 s;
"a" f;
}
}
==== Source: C.sol ====
import {s, f} from "A.sol";
function s(string memory) pure returns (string memory) {}
function f(string memory) pure suffix returns (string memory) {}
contract D {
function run() public pure {
1024 s;
"a" f;
}
}
@@ -0,0 +1,13 @@
function suffix256(uint) pure suffix returns (bool) {}
function suffix256(uint, uint) pure suffix returns (address) {}
function suffix8(uint) pure suffix returns (bool) {}
function suffix8(uint8, uint) pure suffix returns (address) {}
contract C {
// Not ambiguous: no way to convert 1.1 into uint.
address a = 1.1 suffix256;
// Not ambiguous: 1024 won't fit into uint8.
bool b = 1024 suffix8;
}
@@ -0,0 +1,10 @@
function suffix(uint) pure suffix returns (bool) {}
function suffix(uint, uint) pure suffix returns (address) {}
contract C {
function f() public pure {
int a = 1 suffix;
}
}
// ----
// TypeError 4487: (176-182): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,19 @@
function uSuffix(uint8) pure suffix returns (uint) {}
function uSuffix(uint16) pure suffix returns (int) {}
function iSuffix(int8) pure suffix returns (uint) {}
function iSuffix(int16) pure suffix returns (int) {}
function iuSuffix(uint8) pure suffix returns (int) {}
function iuSuffix(int8) pure suffix returns (uint) {}
contract C {
int a = 1024 uSuffix;
int b = 1024 iSuffix;
int c = -1024 uSuffix;
int d = -1024 iSuffix;
int e = 255 iuSuffix;
int f = -255 iuSuffix;
}
@@ -0,0 +1,8 @@
function iuSuffix(uint8) pure suffix returns (int) {}
function iuSuffix(int8) pure suffix returns (int) {}
contract C {
int a = 127 iuSuffix;
}
// ----
// TypeError 4487: (137-145): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,8 @@
function uSuffix(uint8) pure suffix returns (int) {}
function uSuffix(uint16) pure suffix returns (int) {}
contract C {
int a = 127 uSuffix;
}
// ----
// TypeError 4487: (137-144): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,4 @@
function suffix(uint) pure suffix returns (int) {}
function suffix(bool) pure suffix returns (bool) {}
function suffix(address) pure suffix returns (address) {}
function suffix(string memory) pure suffix returns (string memory) {}
@@ -0,0 +1,4 @@
function s(uint) pure suffix returns (uint) {}
function s(uint) pure returns (uint) {}
// ----
// DeclarationError 1686: (0-46): Function with same name and parameter types defined twice.
@@ -0,0 +1,15 @@
==== Source: A.sol ====
function suffix(int, uint) pure suffix returns (int) {}
function suffix(bool) pure suffix returns (bool) {}
function suffix(address) pure suffix returns (address) {}
function suffix(string memory) pure suffix returns (string memory) {}
==== Source: B.sol ====
import "A.sol" as A;
contract C {
int a = 1 A.suffix;
bool b = true A.suffix;
address c = 0x1234567890123456789012345678901234567890 A.suffix;
string d = "a" A.suffix;
}
@@ -0,0 +1,6 @@
function suffix(string memory) pure suffix returns (string memory) {}
function suffix(bytes memory) pure suffix returns (bytes memory) {}
contract C {
bytes a = hex"abcd" suffix;
}
@@ -0,0 +1,8 @@
function suffix(string memory) pure suffix returns (uint) {}
function suffix(bytes memory) pure suffix returns (uint) {}
contract C {
uint a = "abcd" suffix;
}
// ----
// TypeError 4487: (155-161): No unique declaration found after argument-dependent lookup.
@@ -0,0 +1,11 @@
function suffix(uint) pure suffix returns (int) {}
function suffix(bool) pure suffix returns (bool) {}
function suffix(address) pure suffix returns (address) {}
function suffix(string memory) pure suffix returns (string memory) {}
contract C {
int a = suffix(1);
bool b = suffix(true);
address c = suffix(0x1234567890123456789012345678901234567890);
string d = suffix("a");
}
@@ -0,0 +1,14 @@
library L {
function suffix(uint8) internal pure returns (uint8) {}
function suffix(uint16) internal pure returns (bytes16) {}
}
contract C {
using L for uint8;
function f(uint8 x) public {
1 x.suffix;
}
}
// ----
// TypeError 9582: (218-226): Member "suffix" not found or not visible after argument-dependent lookup in uint8.
@@ -0,0 +1,10 @@
abstract contract C {
function suffix(uint8) internal pure virtual returns (uint8);
function suffix(uint16) internal pure virtual returns (bytes16);
function f() public {
1 suffix;
}
}
// ----
// TypeError 9322: (194-200): No matching declaration found after argument-dependent lookup.
@@ -0,0 +1,16 @@
function calldataSuffix(string memory s) pure suffix returns (string memory) {}
function memorySuffix(string calldata s) pure suffix returns (string memory) {}
function storageSuffix(string storage s) pure suffix returns (string memory) {}
contract C {
function f() public pure {
"a" calldataSuffix;
"a" memorySuffix; // OK
"a" storageSuffix;
}
}
// ----
// TypeError 2998: (102-119): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (183-199): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 8838: (321-324): The literal cannot be converted to type string calldata accepted by the suffix function.
// TypeError 8838: (353-356): The literal cannot be converted to type string storage pointer accepted by the suffix function.
@@ -0,0 +1,29 @@
type T is uint;
interface I {}
enum E { A, B, C }
struct S { uint x; }
contract C {}
function payableSuffix(address payable) pure suffix returns (uint) {}
function internalFunctionSuffix(function () internal) pure suffix returns (uint) {}
function externalFunctionSuffix(function () external) pure suffix returns (uint) {}
function mappingSuffix(mapping(uint => uint) storage) pure suffix returns (uint) {}
function udvtSuffix(T) pure suffix returns (uint) {}
function enumSuffix(E) pure suffix returns (uint) {}
function structSuffix(S memory) pure suffix returns (uint) {}
function interfaceSuffix(I) pure suffix returns (uint) {}
function contractSuffix(C) pure suffix returns (uint) {}
function staticArraySuffix(uint[3] memory) pure suffix returns (uint) {}
function dynamicArraySuffix(uint[] memory) pure suffix returns (uint) {}
// ----
// TypeError 2998: (109-124): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (188-209): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (272-293): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (347-376): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (428-429): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (481-482): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (536-544): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (601-602): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (658-659): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (718-732): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 2998: (792-805): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
@@ -0,0 +1,25 @@
struct S {
uint x;
}
function structSuffix(uint x) pure suffix returns (S calldata s) {
assembly {
s := x
}
}
function arraySuffix(uint x) pure suffix returns (uint[5] calldata a) {
assembly {
a := x
}
}
contract C {
function f() public pure {
1 structSuffix;
1 arraySuffix;
}
}
// ----
// TypeError 7251: (77-89): Literal suffix functions can only return value types and reference types stored in memory.
// TypeError 7251: (182-200): Literal suffix functions can only return value types and reference types stored in memory.
@@ -0,0 +1,13 @@
struct S {
uint x;
}
function structSuffix(uint x) pure suffix returns (S memory s) {}
function arraySuffix(uint x) pure suffix returns (uint[5] memory a) {}
contract C {
function f() public pure {
1 structSuffix;
1 arraySuffix;
}
}
@@ -0,0 +1,33 @@
struct S {
uint x;
}
function structSuffix(uint x) pure suffix returns (S storage s) {
assembly ("memory-safe") {
s.slot := x
}
}
function arraySuffix(uint x) pure suffix returns (uint[5] storage a) {
assembly ("memory-safe") {
a.slot := x
}
}
function mappingSuffix(uint x) pure suffix returns (mapping(uint => uint) storage m) {
assembly ("memory-safe") {
m.slot := x
}
}
contract C {
function f() public pure {
1 structSuffix;
1 arraySuffix;
1 mappingSuffix;
}
}
// ----
// TypeError 7251: (77-88): Literal suffix functions can only return value types and reference types stored in memory.
// TypeError 7251: (202-219): Literal suffix functions can only return value types and reference types stored in memory.
// TypeError 7251: (335-366): Literal suffix functions can only return value types and reference types stored in memory.
@@ -0,0 +1,38 @@
function s8(uint mantissa, int8 exponent) pure suffix returns (uint) { }
function s64(uint mantissa, int64 exponent) pure suffix returns (uint) { }
function s160(uint mantissa, int160 exponent) pure suffix returns (uint) { }
function s256(uint mantissa, int256 exponent) pure suffix returns (uint) { }
function ms64(int64 mantissa, int8 exponent) pure suffix returns (uint) { }
function ms160(int160 mantissa, int160 exponent) pure suffix returns (uint) { }
function ms256(int256 mantissa, int256 exponent) pure suffix returns (uint) { }
function mu64(uint64 mantissa, int8 exponent) pure suffix returns (uint) { }
function mu160(uint160 mantissa, int160 exponent) pure suffix returns (uint) { }
function mu256(uint256 mantissa, int256 exponent) pure suffix returns (uint) { }
contract C {
function f() public pure {
3.1415 s8;
3.1415 s64;
3.1415 s160;
3.1415 s256;
1.6180 ms64;
1.6180 ms160;
1.6180 ms256;
2.7182 mu64;
2.7182 mu160;
2.7182 mu256;
}
}
// ----
// TypeError 3123: (27-31): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (101-106): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (177-183): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (254-260): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (332-336): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (410-416): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (490-496): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (569-573): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (648-654): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
// TypeError 3123: (729-735): The exponent parameter of a literal suffix function must be unsigned. Exponent is always either zero or a negative power of 10 but the parameter represents its absolute value.
@@ -0,0 +1,11 @@
function zero() pure suffix returns (uint) { return 1; }
contract C {
function f() public pure {
1 zero; // No error here, only at suffix definition.
1.1 zero; // No error here, only at suffix definition.
"a" zero; // No error here, only at suffix definition.
}
}
// ----
// TypeError 9128: (13-15): Only functions that take one or two arguments can be used as literal suffixes.
@@ -0,0 +1,30 @@
function uintUintUintSuffix(uint, uint, uint) pure suffix returns (uint) { return 1; }
function stringStringStringSuffix(string memory, string memory, string memory) pure suffix returns (uint) { return 1; }
function uintStringSuffix(uint, string memory) pure suffix returns (uint) { return 1; }
function stringUintSuffix(string memory, uint) pure suffix returns (uint) { return 1; }
contract C {
function f() public pure {
1 uintUintUintSuffix;
1 stringStringStringSuffix;
1 uintStringSuffix;
1 stringUintSuffix;
1.1 uintUintUintSuffix;
1.1 stringStringStringSuffix;
1.1 uintStringSuffix;
1.1 stringUintSuffix;
"a" uintUintUintSuffix;
"a" stringStringStringSuffix;
"a" uintStringSuffix; // Error both here and at suffix definition.
"a" stringUintSuffix; // Error both here and at suffix definition.
}
}
// ----
// TypeError 9128: (27-45): Only functions that take one or two arguments can be used as literal suffixes.
// TypeError 9128: (120-165): Only functions that take one or two arguments can be used as literal suffixes.
// TypeError 1587: (232-253): Literal suffix function has invalid parameter types. The exponent parameter must be an unsigned integer.
// TypeError 1587: (320-341): Literal suffix function has invalid parameter types. The mantissa parameter must be an integer.
// TypeError 2505: (764-780): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
// TypeError 2505: (849-865): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
@@ -0,0 +1,6 @@
type M is int;
type E is uint;
function suffix(M x, E y) pure suffix returns (M) {}
// ----
// TypeError 1587: (47-57): Literal suffix function has invalid parameter types. The mantissa parameter must be an integer. The exponent parameter must be an unsigned integer.
@@ -0,0 +1,106 @@
function uintSuffix(uint) pure suffix returns (uint) { return 1; }
function int8Suffix(int8) pure suffix returns (uint) { return 1; }
function boolSuffix(bool) pure suffix returns (uint) { return 1; }
function addressSuffix(address) pure suffix returns (uint) { return 1; }
function decimalSuffix(uint, uint) pure suffix returns (uint) { return 1; }
function stringSuffix(string memory) pure suffix returns (uint) { return 1; }
function bytesSuffix(bytes memory) pure suffix returns (uint) { return 1; }
contract C {
function f() public pure {
1 uintSuffix; // allowed
1 int8Suffix; // allowed
1 boolSuffix;
1 addressSuffix;
1 decimalSuffix; // allowed
1 stringSuffix;
1 bytesSuffix;
1024 uintSuffix; // allowed
1024 int8Suffix;
1024 boolSuffix;
1024 addressSuffix;
1024 decimalSuffix; // allowed
1024 stringSuffix;
1024 bytesSuffix;
true uintSuffix;
true int8Suffix;
true boolSuffix; // allowed
true addressSuffix;
true decimalSuffix;
true stringSuffix;
true bytesSuffix;
0x1234567890123456789012345678901234567890 uintSuffix;
0x1234567890123456789012345678901234567890 int8Suffix;
0x1234567890123456789012345678901234567890 boolSuffix;
0x1234567890123456789012345678901234567890 addressSuffix; // allowed
0x1234567890123456789012345678901234567890 decimalSuffix;
0x1234567890123456789012345678901234567890 stringSuffix;
0x1234567890123456789012345678901234567890 bytesSuffix;
1.1 uintSuffix;
1.1 int8Suffix;
1.1 boolSuffix;
1.1 addressSuffix;
1.1 decimalSuffix; // allowed
1.1 stringSuffix;
1.1 bytesSuffix;
"a" uintSuffix;
"a" int8Suffix;
"a" boolSuffix;
"a" addressSuffix;
"a" decimalSuffix;
"a" stringSuffix; // allowed
"a" bytesSuffix; // allowed
hex"abcd" uintSuffix;
hex"abcd" int8Suffix;
hex"abcd" boolSuffix;
hex"abcd" addressSuffix;
hex"abcd" decimalSuffix;
hex"abcd" stringSuffix;
hex"abcd" bytesSuffix; // allowed
}
}
// ----
// TypeError 8838: (635-636): The number cannot be converted to type bool accepted by the suffix function.
// TypeError 8838: (657-658): The number cannot be converted to type address accepted by the suffix function.
// TypeError 8838: (721-722): The number cannot be converted to type string memory accepted by the suffix function.
// TypeError 8838: (745-746): The number cannot be converted to type bytes memory accepted by the suffix function.
// TypeError 8838: (808-812): The number is out of range of type int8 accepted by the suffix function.
// TypeError 8838: (833-837): The number cannot be converted to type bool accepted by the suffix function.
// TypeError 8838: (858-862): The number cannot be converted to type address accepted by the suffix function.
// TypeError 8838: (925-929): The number cannot be converted to type string memory accepted by the suffix function.
// TypeError 8838: (952-956): The number cannot be converted to type bytes memory accepted by the suffix function.
// TypeError 8838: (979-983): The literal cannot be converted to type uint256 accepted by the suffix function.
// TypeError 8838: (1004-1008): The literal cannot be converted to type int8 accepted by the suffix function.
// TypeError 8838: (1068-1072): The literal cannot be converted to type address accepted by the suffix function.
// TypeError 2505: (1101-1114): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
// TypeError 8838: (1124-1128): The literal cannot be converted to type string memory accepted by the suffix function.
// TypeError 8838: (1151-1155): The literal cannot be converted to type bytes memory accepted by the suffix function.
// TypeError 8838: (1178-1220): The address cannot be converted to type uint256 accepted by the suffix function.
// TypeError 8838: (1241-1283): The address cannot be converted to type int8 accepted by the suffix function.
// TypeError 8838: (1304-1346): The address cannot be converted to type bool accepted by the suffix function.
// TypeError 2505: (1487-1500): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
// TypeError 8838: (1510-1552): The address cannot be converted to type string memory accepted by the suffix function.
// TypeError 8838: (1575-1617): The address cannot be converted to type bytes memory accepted by the suffix function.
// TypeError 8838: (1640-1643): The number cannot be converted to type uint256 accepted by the suffix function.
// TypeError 8838: (1664-1667): The number cannot be converted to type int8 accepted by the suffix function.
// TypeError 8838: (1688-1691): The number cannot be converted to type bool accepted by the suffix function.
// TypeError 8838: (1712-1715): The number cannot be converted to type address accepted by the suffix function.
// TypeError 8838: (1777-1780): The number cannot be converted to type string memory accepted by the suffix function.
// TypeError 8838: (1803-1806): The number cannot be converted to type bytes memory accepted by the suffix function.
// TypeError 8838: (1829-1832): The literal cannot be converted to type uint256 accepted by the suffix function.
// TypeError 8838: (1853-1856): The literal cannot be converted to type int8 accepted by the suffix function.
// TypeError 8838: (1877-1880): The literal cannot be converted to type bool accepted by the suffix function.
// TypeError 8838: (1901-1904): The literal cannot be converted to type address accepted by the suffix function.
// TypeError 2505: (1932-1945): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
// TypeError 8838: (2032-2041): The literal cannot be converted to type uint256 accepted by the suffix function.
// TypeError 8838: (2062-2071): The literal cannot be converted to type int8 accepted by the suffix function.
// TypeError 8838: (2092-2101): The literal cannot be converted to type bool accepted by the suffix function.
// TypeError 8838: (2122-2131): The literal cannot be converted to type address accepted by the suffix function.
// TypeError 2505: (2165-2178): Functions that take 2 arguments can only be used as literal suffixes for rational numbers.
// TypeError 8838: (2188-2197): The literal cannot be converted to type string memory accepted by the suffix function.
@@ -0,0 +1,20 @@
function uintUintSuffix(uint x) pure suffix returns (uint, uint) { return (x, x); }
contract C {
function g(uint, uint) public {}
function f() public {
abi.encode(1 uintUintSuffix);
abi.encodePacked(2 uintUintSuffix);
abi.encodeWithSelector(0x12345678, 3 uintUintSuffix);
abi.encodeWithSignature("f()", 4 uintUintSuffix);
abi.encodeCall(this.g, 5 uintUintSuffix);
}
}
// ----
// TypeError 7848: (52-64): Literal suffix functions must return exactly one value.
// TypeError 2056: (181-197): This type cannot be encoded.
// TypeError 2056: (225-241): This type cannot be encoded.
// TypeError 2056: (287-303): This type cannot be encoded.
// TypeError 2056: (345-361): This type cannot be encoded.
// TypeError 9062: (395-411): Expected an inline tuple, not an expression of a tuple type.
@@ -0,0 +1,23 @@
function nullSuffix(uint) pure suffix {}
contract C {
function g() public {}
function h() public returns (uint, uint) {}
event E();
function f() public {
abi.encode(1 nullSuffix);
abi.encodePacked(2 nullSuffix);
abi.encodeWithSelector(0x12345678, 3 nullSuffix);
abi.encodeWithSignature("f()", 4 nullSuffix);
abi.encodeCall(this.g, 5 nullSuffix);
}
}
// ----
// TypeError 7848: (38-38): Literal suffix functions must return exactly one value.
// TypeError 2056: (192-204): This type cannot be encoded.
// TypeError 2056: (232-244): This type cannot be encoded.
// TypeError 2056: (290-302): This type cannot be encoded.
// TypeError 2056: (344-356): This type cannot be encoded.
// TypeError 9062: (390-402): Expected an inline tuple, not an expression of a tuple type.
@@ -0,0 +1,3 @@
error E1(uint) suffix;
// ----
// ParserError 2314: (15-21): Expected ';' but got identifier
@@ -0,0 +1,5 @@
contract C {
event E(uint) suffix;
}
// ----
// ParserError 2314: (31-37): Expected ';' but got identifier
@@ -0,0 +1,5 @@
contract C {
function f(uint) internal pure suffix returns (uint) {}
}
// ----
// DeclarationError 7920: (48-54): Identifier not found or not unique.
@@ -0,0 +1,6 @@
interface I {
function f(uint) external pure suffix returns (uint) {}
}
// ----
// SyntaxError 5842: (18-73): Functions in interfaces cannot have modifiers.
// DeclarationError 7920: (49-55): Identifier not found or not unique.
@@ -0,0 +1,5 @@
library L {
function f(uint) internal pure suffix returns (uint) {}
}
// ----
// DeclarationError 7920: (47-53): Identifier not found or not unique.
@@ -0,0 +1,5 @@
contract C {
function (uint) pure suffix returns (uint) ptr;
}
// ----
// ParserError 2314: (45-52): Expected ';' but got 'returns'
@@ -0,0 +1,9 @@
function suffix1(uint) pure suffix suffix returns (uint) {}
function suffix2(uint) suffix pure suffix returns (uint) {}
function suffix3(uint) suffix pure suffix suffix suffix returns (uint) {}
// ----
// ParserError 2878: (35-41): Suffix already specified.
// ParserError 2878: (95-101): Suffix already specified.
// ParserError 2878: (155-161): Suffix already specified.
// ParserError 2878: (162-168): Suffix already specified.
// ParserError 2878: (169-175): Suffix already specified.
@@ -0,0 +1,5 @@
contract C {
modifier m(uint) suffix {}
}
// ----
// ParserError 2314: (34-40): Expected '{' but got identifier
@@ -0,0 +1,5 @@
contract C {
uint suffix a;
}
// ----
// ParserError 2314: (29-30): Expected ';' but got identifier
@@ -0,0 +1,2 @@
function suffix1(uint) pure suffix returns (uint) {}
function suffix2(uint) suffix pure returns (uint) {}
@@ -0,0 +1,22 @@
function s(uint value) pure suffix returns (uint) { return value; }
function z(uint value) pure suffix returns (uint) { return value; }
function q(uint value) pure suffix returns (uint) { return value; }
contract C {
address z;
function q() internal {}
function f() public {
uint s;
1 s;
2 z;
3 q;
}
}
// ----
// Warning 2519: (298-304): This declaration shadows an existing declaration.
// Warning 2519: (222-231): This declaration shadows an existing declaration.
// Warning 2519: (238-262): This declaration shadows an existing declaration.
// TypeError 5704: (315-318): This expression cannot be used as a literal suffix.
@@ -0,0 +1,27 @@
function s(uint x) pure suffix returns (uint) { return x; }
function S(uint x) pure suffix returns (uint) { return x; }
function suffix(uint x) pure suffix returns (uint) { return x; }
function SUFFIX(uint x) pure suffix returns (uint) { return x; }
function suffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffix(uint x) pure suffix returns (uint) { return x; }
function __(uint x) pure suffix returns (uint) { return x; }
function _____________________________________(uint x) pure suffix returns (uint) { return x; }
function _s_(uint x) pure suffix returns (uint) { return x; }
function $(uint x) pure suffix returns (uint) { return x; }
function _$(uint x) pure suffix returns (uint) { return x; }
function abcdef(uint x) pure suffix returns (uint) { return x; }
contract C {
function f() public pure {
1000 s;
1000 S;
1000 suffix;
1000 SUFFIX;
1000 suffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffix;
1000 __;
1000 _____________________________________;
1000 _s_;
1000 $;
1000 _$;
0x1000_abcdef abcdef;
}
}
@@ -0,0 +1,10 @@
function suffix(address payable a) pure suffix returns (address payable) { return a; }
contract C {
function f() public pure {
0x1234567890123456789012345678901234567890 suffix;
}
}
// ----
// TypeError 2998: (16-33): This literal suffix function is not usable as a suffix because no literal is implicitly convertible to its parameter type.
// TypeError 8838: (140-182): The address cannot be converted to type address payable accepted by the suffix function.

Some files were not shown because too many files have changed in this diff Show More