mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
User-defined literal suffixes: Tests
This commit is contained in:
parent
cbd0da426c
commit
5edad8f450
263
test/libsolidity/ASTJSON/literalSuffix.json
Normal file
263
test/libsolidity/ASTJSON/literalSuffix.json
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
{
|
||||||
|
"absolutePath": "a",
|
||||||
|
"exportedSymbols":
|
||||||
|
{
|
||||||
|
"C":
|
||||||
|
[
|
||||||
|
16
|
||||||
|
],
|
||||||
|
"str":
|
||||||
|
[
|
||||||
|
10
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"id": 17,
|
||||||
|
"nodeType": "SourceUnit",
|
||||||
|
"nodes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"body":
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"nodeType": "Block",
|
||||||
|
"src": "63:2:1",
|
||||||
|
"statements": []
|
||||||
|
},
|
||||||
|
"id": 10,
|
||||||
|
"implemented": true,
|
||||||
|
"kind": "freeFunction",
|
||||||
|
"modifiers": [],
|
||||||
|
"name": "str",
|
||||||
|
"nameLocation": "9:3:1",
|
||||||
|
"nodeType": "FunctionDefinition",
|
||||||
|
"parameters":
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"nodeType": "ParameterList",
|
||||||
|
"parameters":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 2,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "",
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"scope": 10,
|
||||||
|
"src": "13:6:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "default",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_uint32",
|
||||||
|
"typeString": "uint32"
|
||||||
|
},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "uint32",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "13:6:1",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_uint32",
|
||||||
|
"typeString": "uint32"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 4,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "",
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"scope": 10,
|
||||||
|
"src": "21:4:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "default",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_uint256",
|
||||||
|
"typeString": "uint256"
|
||||||
|
},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "uint",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "21:4:1",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_uint256",
|
||||||
|
"typeString": "uint256"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "12:14:1"
|
||||||
|
},
|
||||||
|
"returnParameters":
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"nodeType": "ParameterList",
|
||||||
|
"parameters":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 7,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "",
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"scope": 10,
|
||||||
|
"src": "48:13:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "memory",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_string_memory_ptr",
|
||||||
|
"typeString": "string"
|
||||||
|
},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"name": "string",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "48:6:1",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_string_storage_ptr",
|
||||||
|
"typeString": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "47:15:1"
|
||||||
|
},
|
||||||
|
"scope": 17,
|
||||||
|
"src": "0:65:1",
|
||||||
|
"stateMutability": "pure",
|
||||||
|
"suffix": true,
|
||||||
|
"virtual": false,
|
||||||
|
"visibility": "internal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"abstract": false,
|
||||||
|
"baseContracts": [],
|
||||||
|
"canonicalName": "C",
|
||||||
|
"contractDependencies": [],
|
||||||
|
"contractKind": "contract",
|
||||||
|
"fullyImplemented": true,
|
||||||
|
"id": 16,
|
||||||
|
"linearizedBaseContracts":
|
||||||
|
[
|
||||||
|
16
|
||||||
|
],
|
||||||
|
"name": "C",
|
||||||
|
"nameLocation": "75:1:1",
|
||||||
|
"nodeType": "ContractDefinition",
|
||||||
|
"nodes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 15,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "s",
|
||||||
|
"nameLocation": "90:1:1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"scope": 16,
|
||||||
|
"src": "83:26:1",
|
||||||
|
"stateVariable": true,
|
||||||
|
"storageLocation": "default",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_string_storage",
|
||||||
|
"typeString": "string"
|
||||||
|
},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"name": "string",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "83:6:1",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_string_storage_ptr",
|
||||||
|
"typeString": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"arguments":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"hexValue": "3132332e3334355f373839",
|
||||||
|
"id": 12,
|
||||||
|
"isConstant": false,
|
||||||
|
"isLValue": false,
|
||||||
|
"isPure": true,
|
||||||
|
"kind": "number",
|
||||||
|
"lValueRequested": false,
|
||||||
|
"nodeType": "Literal",
|
||||||
|
"src": "94:11:1",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_rational_123345789_by_1000000",
|
||||||
|
"typeString": "rational_const 123345789 / 1000000"
|
||||||
|
},
|
||||||
|
"value": "123.345_789"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"expression":
|
||||||
|
{
|
||||||
|
"argumentTypes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_rational_123345789_by_1000000",
|
||||||
|
"typeString": "rational_const 123345789 / 1000000"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": 13,
|
||||||
|
"name": "str",
|
||||||
|
"nodeType": "Identifier",
|
||||||
|
"overloadedDeclarations": [],
|
||||||
|
"referencedDeclaration": 10,
|
||||||
|
"src": "106:3:1",
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_function_internal_pure$_t_uint32_$_t_uint256_$returns$_t_string_memory_ptr_$",
|
||||||
|
"typeString": "function (uint32,uint256) pure returns (string memory)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"id": 14,
|
||||||
|
"isConstant": false,
|
||||||
|
"isLValue": false,
|
||||||
|
"isPure": false,
|
||||||
|
"isSuffixCall": true,
|
||||||
|
"kind": "functionCall",
|
||||||
|
"lValueRequested": false,
|
||||||
|
"nameLocations": [],
|
||||||
|
"names": [],
|
||||||
|
"nodeType": "FunctionCall",
|
||||||
|
"src": "94:15:1",
|
||||||
|
"tryCall": false,
|
||||||
|
"typeDescriptions":
|
||||||
|
{
|
||||||
|
"typeIdentifier": "t_string_memory_ptr",
|
||||||
|
"typeString": "string memory"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"scope": 17,
|
||||||
|
"src": "66:46:1",
|
||||||
|
"usedErrors": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "0:113:1"
|
||||||
|
}
|
6
test/libsolidity/ASTJSON/literalSuffix.sol
Normal file
6
test/libsolidity/ASTJSON/literalSuffix.sol
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
function str(uint32, uint) pure suffix returns (string memory) {}
|
||||||
|
contract C {
|
||||||
|
string s = 123.345_789 str;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
179
test/libsolidity/ASTJSON/literalSuffix_parseOnly.json
Normal file
179
test/libsolidity/ASTJSON/literalSuffix_parseOnly.json
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
{
|
||||||
|
"absolutePath": "a",
|
||||||
|
"id": 17,
|
||||||
|
"nodeType": "SourceUnit",
|
||||||
|
"nodes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"body":
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"nodeType": "Block",
|
||||||
|
"src": "63:2:1",
|
||||||
|
"statements": []
|
||||||
|
},
|
||||||
|
"id": 10,
|
||||||
|
"implemented": true,
|
||||||
|
"kind": "freeFunction",
|
||||||
|
"modifiers": [],
|
||||||
|
"name": "str",
|
||||||
|
"nameLocation": "9:3:1",
|
||||||
|
"nodeType": "FunctionDefinition",
|
||||||
|
"parameters":
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"nodeType": "ParameterList",
|
||||||
|
"parameters":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 2,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "",
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"src": "13:6:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "default",
|
||||||
|
"typeDescriptions": {},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "uint32",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "13:6:1",
|
||||||
|
"typeDescriptions": {}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 4,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "",
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"src": "21:4:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "default",
|
||||||
|
"typeDescriptions": {},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "uint",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "21:4:1",
|
||||||
|
"typeDescriptions": {}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "12:14:1"
|
||||||
|
},
|
||||||
|
"returnParameters":
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"nodeType": "ParameterList",
|
||||||
|
"parameters":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 7,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "",
|
||||||
|
"nameLocation": "-1:-1:-1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"src": "48:13:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "memory",
|
||||||
|
"typeDescriptions": {},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"name": "string",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "48:6:1",
|
||||||
|
"typeDescriptions": {}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "47:15:1"
|
||||||
|
},
|
||||||
|
"src": "0:65:1",
|
||||||
|
"stateMutability": "pure",
|
||||||
|
"suffix": true,
|
||||||
|
"virtual": false,
|
||||||
|
"visibility": "internal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"abstract": false,
|
||||||
|
"baseContracts": [],
|
||||||
|
"contractDependencies": [],
|
||||||
|
"contractKind": "contract",
|
||||||
|
"id": 16,
|
||||||
|
"name": "C",
|
||||||
|
"nameLocation": "75:1:1",
|
||||||
|
"nodeType": "ContractDefinition",
|
||||||
|
"nodes":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"constant": false,
|
||||||
|
"id": 15,
|
||||||
|
"mutability": "mutable",
|
||||||
|
"name": "s",
|
||||||
|
"nameLocation": "90:1:1",
|
||||||
|
"nodeType": "VariableDeclaration",
|
||||||
|
"src": "83:26:1",
|
||||||
|
"stateVariable": false,
|
||||||
|
"storageLocation": "default",
|
||||||
|
"typeDescriptions": {},
|
||||||
|
"typeName":
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"name": "string",
|
||||||
|
"nodeType": "ElementaryTypeName",
|
||||||
|
"src": "83:6:1",
|
||||||
|
"typeDescriptions": {}
|
||||||
|
},
|
||||||
|
"value":
|
||||||
|
{
|
||||||
|
"arguments":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"hexValue": "3132332e3334355f373839",
|
||||||
|
"id": 12,
|
||||||
|
"kind": "number",
|
||||||
|
"nodeType": "Literal",
|
||||||
|
"src": "94:11:1",
|
||||||
|
"typeDescriptions": {},
|
||||||
|
"value": "123.345_789"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"expression":
|
||||||
|
{
|
||||||
|
"id": 13,
|
||||||
|
"name": "str",
|
||||||
|
"nodeType": "Identifier",
|
||||||
|
"overloadedDeclarations": [],
|
||||||
|
"src": "106:3:1",
|
||||||
|
"typeDescriptions": {}
|
||||||
|
},
|
||||||
|
"id": 14,
|
||||||
|
"isSuffixCall": true,
|
||||||
|
"nameLocations": [],
|
||||||
|
"names": [],
|
||||||
|
"nodeType": "FunctionCall",
|
||||||
|
"src": "94:15:1",
|
||||||
|
"tryCall": false,
|
||||||
|
"typeDescriptions": {}
|
||||||
|
},
|
||||||
|
"visibility": "internal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "66:46:1",
|
||||||
|
"usedErrors": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"src": "0:113:1"
|
||||||
|
}
|
@ -967,6 +967,49 @@ BOOST_AUTO_TEST_CASE(modifiers)
|
|||||||
checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges, expectedCreatedContractsAfterDeployment);
|
checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges, expectedCreatedContractsAfterDeployment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(literal_suffixes)
|
||||||
|
{
|
||||||
|
unique_ptr<CompilerStack> compilerStack = parseAndAnalyzeContracts(R"(
|
||||||
|
function free() pure {}
|
||||||
|
function intSuffix(uint) pure suffix returns (uint) { free(); return 1; }
|
||||||
|
function strSuffix(string memory) pure suffix returns (uint) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
modifier m(uint) virtual { _; }
|
||||||
|
|
||||||
|
constructor() m(1 intSuffix) { "a" strSuffix; }
|
||||||
|
function ext() external pure m("a" strSuffix) { 1 intSuffix; inr(); }
|
||||||
|
function inr() internal pure { 1 intSuffix; }
|
||||||
|
}
|
||||||
|
)"s);
|
||||||
|
tuple<CallGraphMap, CallGraphMap> graphs = collectGraphs(*compilerStack);
|
||||||
|
|
||||||
|
map<string, EdgeNames> expectedCreationEdges = {
|
||||||
|
{"C", {
|
||||||
|
{"Entry", "constructor of C"},
|
||||||
|
{"constructor of C", "modifier C.m"},
|
||||||
|
{"constructor of C", "function intSuffix(uint256)"},
|
||||||
|
{"constructor of C", "function strSuffix(string)"},
|
||||||
|
{"function intSuffix(uint256)", "function free()"},
|
||||||
|
}},
|
||||||
|
};
|
||||||
|
|
||||||
|
map<string, EdgeNames> expectedDeployedEdges = {
|
||||||
|
{"C", {
|
||||||
|
{"Entry", "function C.ext()"},
|
||||||
|
{"function C.ext()", "modifier C.m"},
|
||||||
|
{"function C.ext()", "function C.inr()"},
|
||||||
|
{"function C.ext()", "function strSuffix(string)"},
|
||||||
|
{"function C.ext()", "function intSuffix(uint256)"},
|
||||||
|
{"function C.inr()", "function intSuffix(uint256)"},
|
||||||
|
{"function intSuffix(uint256)", "function free()"},
|
||||||
|
}},
|
||||||
|
};
|
||||||
|
|
||||||
|
checkCallGraphExpectations(get<0>(graphs), expectedCreationEdges);
|
||||||
|
checkCallGraphExpectations(get<1>(graphs), expectedDeployedEdges);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(events)
|
BOOST_AUTO_TEST_CASE(events)
|
||||||
{
|
{
|
||||||
unique_ptr<CompilerStack> compilerStack = parseAndAnalyzeContracts(R"(
|
unique_ptr<CompilerStack> compilerStack = parseAndAnalyzeContracts(R"(
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
function f(uint x) pure returns (uint) {
|
||||||
|
return 21 * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
function suffix(uint) pure suffix returns (function(uint) returns (uint)) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public returns (uint) {
|
||||||
|
return (1 suffix)(2) + 1 suffix(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 63
|
@ -0,0 +1,18 @@
|
|||||||
|
function checkedSuffix(uint8 x) pure suffix returns (uint8) {
|
||||||
|
return x + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testCheckedSuffix() public pure returns (uint8) {
|
||||||
|
return 250 checkedSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCheckedSuffixInUncheckedBlock() public pure returns (uint8) {
|
||||||
|
unchecked {
|
||||||
|
return 250 checkedSuffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testCheckedSuffix() -> FAILURE, hex"4e487b71", 0x11
|
||||||
|
// testCheckedSuffixInUncheckedBlock() -> FAILURE, hex"4e487b71", 0x11
|
@ -0,0 +1,40 @@
|
|||||||
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
struct Decimal {
|
||||||
|
uint mantissa;
|
||||||
|
uint exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function asDecimal(uint mantissa, uint exponent) pure suffix returns (Decimal memory) {
|
||||||
|
return Decimal(mantissa, exponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function zero() public pure returns (Decimal memory) {
|
||||||
|
return 0.0 asDecimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
function simple() public pure returns (Decimal memory, Decimal memory, Decimal memory, Decimal memory, Decimal memory) {
|
||||||
|
return (
|
||||||
|
1234567800.0 asDecimal,
|
||||||
|
12345678.0 asDecimal,
|
||||||
|
1234.5678 asDecimal,
|
||||||
|
12.345678 asDecimal,
|
||||||
|
0.12345678 asDecimal
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function maxMantissa() public pure returns (Decimal memory) {
|
||||||
|
return 0.00115792089237316195423570985008687907853269984665640564039457584007913129639935e10 asDecimal; // (2**256 - 1) * 10**-(80 - 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
function maxUint8Exponent() public pure returns (Decimal memory) {
|
||||||
|
return 1e-256 asDecimal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// zero() -> 0, 0
|
||||||
|
// simple() -> 1234567800, 0, 12345678, 0, 12345678, 4, 12345678, 6, 12345678, 8
|
||||||
|
// maxMantissa() -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 70
|
||||||
|
// maxUint8Exponent() -> 1, 256
|
@ -0,0 +1,10 @@
|
|||||||
|
function szabo(uint x) pure suffix returns (uint) { return 2 * x; }
|
||||||
|
function finney(uint x) pure suffix returns (uint) { return 4 * x; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
uint public s = 2 szabo;
|
||||||
|
uint public f = 2 finney;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// s() -> 4
|
||||||
|
// f() -> 8
|
@ -0,0 +1,33 @@
|
|||||||
|
function suffix(uint) pure suffix returns (string memory) {
|
||||||
|
return "suffix";
|
||||||
|
}
|
||||||
|
|
||||||
|
library L {
|
||||||
|
function suffix(uint) private pure returns (string memory) {
|
||||||
|
return "library function";
|
||||||
|
}
|
||||||
|
|
||||||
|
function run() public pure returns (string memory) {
|
||||||
|
return suffix(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function suffix(uint) internal pure returns (string memory) {
|
||||||
|
return "contract function";
|
||||||
|
}
|
||||||
|
|
||||||
|
function run() public pure returns (string memory) {
|
||||||
|
return suffix(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function runL() public pure returns (string memory) {
|
||||||
|
return L.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// EVMVersion: >=byzantium
|
||||||
|
// ----
|
||||||
|
// library: L
|
||||||
|
// run() -> 0x20, 0x11, "contract function"
|
||||||
|
// runL() -> 0x20, 0x10, "library function"
|
@ -0,0 +1,33 @@
|
|||||||
|
pragma abicoder v2;
|
||||||
|
|
||||||
|
struct Decimal {
|
||||||
|
uint mantissa;
|
||||||
|
uint exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function asDecimal(uint mantissa, uint exponent) pure suffix returns (Decimal memory) {
|
||||||
|
return Decimal(mantissa, exponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function zero() public pure returns (Decimal memory) {
|
||||||
|
return 0 asDecimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
function simple() public pure returns (Decimal memory, Decimal memory, Decimal memory) {
|
||||||
|
return (
|
||||||
|
1234567800 asDecimal,
|
||||||
|
12345678 asDecimal,
|
||||||
|
1 asDecimal
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function maxMantissa() public pure returns (Decimal memory) {
|
||||||
|
return 115792089237316195423570985008687907853269984665640564039457584007913129639935 asDecimal; // 2**256 - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// zero() -> 0, 0
|
||||||
|
// simple() -> 1234567800, 0, 12345678, 0, 1, 0
|
||||||
|
// maxMantissa() -> 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff, 0
|
@ -0,0 +1,22 @@
|
|||||||
|
type Length is uint;
|
||||||
|
|
||||||
|
function km(uint meters) pure suffix returns (Length) {
|
||||||
|
return Length.wrap(meters * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Float {
|
||||||
|
uint mantissa;
|
||||||
|
uint exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f(uint mantissa, uint exponent) pure suffix returns (Float memory) {
|
||||||
|
return Float(mantissa, exponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
Length public length = 5000 km;
|
||||||
|
Float public factor = 1.23 f;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// length() -> 5000000
|
||||||
|
// factor() -> 0x7b, 2
|
@ -0,0 +1,30 @@
|
|||||||
|
==== Source: builtin.sol ====
|
||||||
|
function builtinKeccak(bytes memory input) pure returns (bytes32) {
|
||||||
|
return keccak256(input);
|
||||||
|
}
|
||||||
|
==== Source: suffix.sol ====
|
||||||
|
import {builtinKeccak} from "builtin.sol";
|
||||||
|
|
||||||
|
function keccak256(bytes memory input) pure suffix returns (bytes32) {
|
||||||
|
// NOTE: A call to keccak256() here would not call the built-in
|
||||||
|
// and would instead result in infinite recursion.
|
||||||
|
return builtinKeccak(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testBuiltin() public pure returns (bytes32) {
|
||||||
|
return builtinKeccak("solidity");
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSuffix() public pure returns (bytes32) {
|
||||||
|
return "solidity" keccak256;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSuffixFunctionCall() public pure returns (bytes32) {
|
||||||
|
return keccak256("solidity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testBuiltin() -> 0xa477d97b122e6356d32a064f9ee824230d42d04c7d66d8e7d125a091a42b0b25
|
||||||
|
// testSuffix() -> 0xa477d97b122e6356d32a064f9ee824230d42d04c7d66d8e7d125a091a42b0b25
|
||||||
|
// testSuffixFunctionCall() -> 0xa477d97b122e6356d32a064f9ee824230d42d04c7d66d8e7d125a091a42b0b25
|
@ -0,0 +1,26 @@
|
|||||||
|
type Bool is bool;
|
||||||
|
using {bitor as |, bitand as &, bitnot as ~} for Bool global;
|
||||||
|
|
||||||
|
function bitor(Bool x, Bool y) pure returns (Bool) {
|
||||||
|
return Bool.wrap(Bool.unwrap(x) || Bool.unwrap(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
function bitand(Bool x, Bool y) pure returns (Bool) {
|
||||||
|
return Bool.wrap(Bool.unwrap(x) && Bool.unwrap(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
function bitnot(Bool x) pure returns (Bool) {
|
||||||
|
return Bool.wrap(!Bool.unwrap(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
function b(bool x) pure suffix returns (Bool) {
|
||||||
|
return Bool.wrap(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public pure returns (Bool) {
|
||||||
|
return ~ ~ ~(false b | true b & ~false b) & true b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> false
|
@ -0,0 +1,26 @@
|
|||||||
|
type Int is int;
|
||||||
|
using {add as +, mul as *, unsub as -} for Int global;
|
||||||
|
|
||||||
|
function add(Int a, Int b) pure returns (Int) {
|
||||||
|
return Int.wrap(Int.unwrap(a) + Int.unwrap(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
function mul(Int a, Int b) pure returns (Int) {
|
||||||
|
return Int.wrap(Int.unwrap(a) * Int.unwrap(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
function unsub(Int a) pure returns (Int) {
|
||||||
|
return Int.wrap(-Int.unwrap(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
function i(int x) pure suffix returns (Int) {
|
||||||
|
return Int.wrap(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public pure returns (Int) {
|
||||||
|
return - - -(4 i + 4 i * -3 i) * 2 i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 16
|
@ -0,0 +1,17 @@
|
|||||||
|
function suffix(uint x) pure suffix returns (uint) { return x; }
|
||||||
|
function suffix(bool x) pure suffix returns (bool) { return x; }
|
||||||
|
function suffix(address x) pure suffix returns (address) { return x; }
|
||||||
|
function suffix(string memory x) pure suffix returns (string memory) { return x; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function run() public returns (bytes memory) {
|
||||||
|
return abi.encode(
|
||||||
|
42 suffix,
|
||||||
|
true suffix,
|
||||||
|
0x1234567890123456789012345678901234567890 suffix,
|
||||||
|
"a" suffix
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// run() -> 0x20, 0xc0, 0x2a, 1, 0x1234567890123456789012345678901234567890, 0x80, 1, "a"
|
@ -0,0 +1,16 @@
|
|||||||
|
function double(uint x) pure suffix returns (uint) {
|
||||||
|
if (x == 0)
|
||||||
|
return 0;
|
||||||
|
if (x == 1)
|
||||||
|
return 0 double + 2;
|
||||||
|
else
|
||||||
|
return 1 double * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public pure returns (uint) {
|
||||||
|
return 10 double;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 20
|
@ -0,0 +1,31 @@
|
|||||||
|
function uintSuffix(uint x) pure suffix returns (uint) { return x; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function g(uint) public {}
|
||||||
|
|
||||||
|
function test() public pure returns (bytes memory) {
|
||||||
|
return abi.encode(1 uintSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPacked() public pure returns (bytes memory) {
|
||||||
|
return abi.encodePacked(2 uintSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testWithSelector() public pure returns (bytes memory) {
|
||||||
|
return abi.encodeWithSelector(0x12345678, 3 uintSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testWithSignature() public pure returns (bytes memory) {
|
||||||
|
return abi.encodeWithSignature("f()", 4 uintSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCall() public view returns (bytes memory) {
|
||||||
|
return abi.encodeCall(this.g, 5 uintSuffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 0x20, 0x20, 1
|
||||||
|
// testPacked() -> 0x20, 0x20, 2
|
||||||
|
// testWithSelector() -> 0x20, 0x24, 0x1234567800000000000000000000000000000000000000000000000000000000, 0x0000000300000000000000000000000000000000000000000000000000000000
|
||||||
|
// testWithSignature() -> 0x20, 0x24, 0x26121ff000000000000000000000000000000000000000000000000000000000, 0x0000000400000000000000000000000000000000000000000000000000000000
|
||||||
|
// testCall() -> 0x20, 0x24, 0xe420264a00000000000000000000000000000000000000000000000000000000, 0x0000000500000000000000000000000000000000000000000000000000000000
|
@ -0,0 +1,9 @@
|
|||||||
|
function selectorSuffix(uint) pure suffix returns (bytes4) { return 0x12345678; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public pure returns (bytes memory) {
|
||||||
|
return abi.encodeWithSelector(1234 selectorSuffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 0x20, 4, 0x1234567800000000000000000000000000000000000000000000000000000000
|
@ -0,0 +1,9 @@
|
|||||||
|
function signatureSuffix(string memory) pure suffix returns (string memory) { return "f()"; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() public pure returns (bytes memory) {
|
||||||
|
return abi.encodeWithSignature("abcd" signatureSuffix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 0x20, 4, 0x26121ff000000000000000000000000000000000000000000000000000000000
|
@ -0,0 +1,9 @@
|
|||||||
|
function twice(uint x) pure suffix returns (uint) { return x * 2; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function run() public pure returns (uint[] memory) {
|
||||||
|
return new uint[](5 twice);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// run() -> 0x20, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
@ -0,0 +1,37 @@
|
|||||||
|
function suffix(int32 x) pure suffix returns (int32) {
|
||||||
|
return loadNegator().negate(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface INegator {
|
||||||
|
function negate(int32) external pure returns (int32);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Negator is INegator {
|
||||||
|
function negate(int32 x) external pure override returns (int32) {
|
||||||
|
return -x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeNegator(INegator negator) pure {
|
||||||
|
assembly {
|
||||||
|
// this test would also work without assembly if we could hard-code an address here.
|
||||||
|
mstore(0, negator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadNegator() pure returns (INegator negator) {
|
||||||
|
assembly {
|
||||||
|
negator := mload(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testSuffix() public returns (int32) {
|
||||||
|
storeNegator(new Negator());
|
||||||
|
|
||||||
|
return 10 suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testSuffix() -> -10
|
||||||
|
// gas legacy: 131793
|
@ -0,0 +1,41 @@
|
|||||||
|
function suffix(int32 x) pure suffix returns (int32) {
|
||||||
|
return loadNegator().negate(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface INegatorPure {
|
||||||
|
function negate(int32) external pure returns (int32);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface INegatorView {
|
||||||
|
function negate(int32) external view returns (int32);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Negator is INegatorView {
|
||||||
|
function negate(int32 x) external view override returns (int32) {
|
||||||
|
return -x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function storeNegator(INegatorView negator) pure {
|
||||||
|
assembly {
|
||||||
|
// this test would also work without assembly if we could hard-code an address here.
|
||||||
|
mstore(0, negator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadNegator() pure returns (INegatorPure negator) {
|
||||||
|
assembly {
|
||||||
|
negator := mload(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testSuffix() public returns (int32) {
|
||||||
|
storeNegator(new Negator());
|
||||||
|
|
||||||
|
return 10 suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testSuffix() -> -10
|
||||||
|
// gas legacy: 131793
|
@ -0,0 +1,29 @@
|
|||||||
|
function suffix(uint8) pure suffix returns (uint8 z) {
|
||||||
|
assembly {
|
||||||
|
// Return a value with dirty bytes outside of uint8
|
||||||
|
z := 0xffff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function test() external pure returns (uint, uint) {
|
||||||
|
uint8 a;
|
||||||
|
|
||||||
|
// The exact literal used does not matter
|
||||||
|
uint8 suffixResult = 1 suffix;
|
||||||
|
uint8 functionResult = suffix(1);
|
||||||
|
|
||||||
|
// Get the whole slot, including bytes outside of uint8
|
||||||
|
uint suffixResultFull;
|
||||||
|
uint functionResultFull;
|
||||||
|
assembly {
|
||||||
|
suffixResultFull := suffixResult
|
||||||
|
functionResultFull := functionResult
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the result is not 0xff, no cleanup was performed.
|
||||||
|
return (suffixResultFull, functionResultFull);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// test() -> 0xffff, 0xffff
|
@ -0,0 +1,46 @@
|
|||||||
|
struct S { uint x; }
|
||||||
|
enum E {A, B, C}
|
||||||
|
type T is uint72;
|
||||||
|
interface I {
|
||||||
|
function f(uint) external pure returns (T);
|
||||||
|
}
|
||||||
|
|
||||||
|
function uintSuffix(uint) pure suffix returns (uint) { return 1234; }
|
||||||
|
function bytes4Suffix(uint) pure suffix returns (bytes4) { return 0x12345678; }
|
||||||
|
function addressSuffix(uint) pure suffix returns (address) { return 0x1111111111222222222233333333334444444444; }
|
||||||
|
function stringSuffix(uint) pure suffix returns (string memory) { return "abcd"; }
|
||||||
|
function bytesSuffix(uint) pure suffix returns (bytes memory) { return "abcd"; }
|
||||||
|
function arraySuffix(uint) pure suffix returns (bytes3[3] memory) { return [bytes3(0x123456), 0x123456, 0x123456]; }
|
||||||
|
function structSuffix(uint) pure suffix returns (S memory) { return S(42); }
|
||||||
|
function enumSuffix(uint) pure suffix returns (E) { return E.C; }
|
||||||
|
function udvtSuffix(uint) pure suffix returns (T) { return T.wrap(42); }
|
||||||
|
function interfaceSuffix(uint) pure suffix returns (I) { return I(address(42)); }
|
||||||
|
function functionSuffix(uint) pure suffix returns (function (uint) external pure returns (T)) { return I(address(0x1111111111222222222233333333334444444444)).f; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
uint public a = 1 uintSuffix;
|
||||||
|
bytes4 public b = 1 bytes4Suffix;
|
||||||
|
address public c = 1 addressSuffix;
|
||||||
|
string public d = 1 stringSuffix;
|
||||||
|
bytes public e = 1 bytesSuffix;
|
||||||
|
bytes3[3] public f = 1 arraySuffix;
|
||||||
|
S public g = 1 structSuffix;
|
||||||
|
E public h = 1 enumSuffix;
|
||||||
|
T public i = 1 udvtSuffix;
|
||||||
|
I public j = 1 interfaceSuffix;
|
||||||
|
function (uint) external pure returns (T) public k = 1 functionSuffix;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// a() -> 1234
|
||||||
|
// b() -> 0x1234567800000000000000000000000000000000000000000000000000000000
|
||||||
|
// c() -> 0x1111111111222222222233333333334444444444
|
||||||
|
// d() -> 0x20, 4, "abcd"
|
||||||
|
// e() -> 0x20, 4, "abcd"
|
||||||
|
// f(uint256): 0 -> 0x1234560000000000000000000000000000000000000000000000000000000000
|
||||||
|
// f(uint256): 1 -> 0x1234560000000000000000000000000000000000000000000000000000000000
|
||||||
|
// f(uint256): 2 -> 0x1234560000000000000000000000000000000000000000000000000000000000
|
||||||
|
// g() -> 42
|
||||||
|
// h() -> 2
|
||||||
|
// i() -> 42
|
||||||
|
// j() -> 42
|
||||||
|
// k() -> 0x1111111111222222222233333333334444444444b3de648b0000000000000000
|
@ -0,0 +1,32 @@
|
|||||||
|
type Int is int;
|
||||||
|
using {sub as -, unsub as -} for Int global;
|
||||||
|
|
||||||
|
function sub(Int a, Int b) pure returns (Int) {
|
||||||
|
return Int.wrap((Int.unwrap(a) - Int.unwrap(b)) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unsub(Int a) pure returns (Int) {
|
||||||
|
return Int.wrap(Int.unwrap(a) + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
function u(int x) pure suffix returns (Int) {
|
||||||
|
return Int.wrap(x + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testUnary() public pure returns (Int) {
|
||||||
|
return -2 u;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testUnaryWithParens() public pure returns (Int) {
|
||||||
|
return -(2 u);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBinary() public pure returns (Int) {
|
||||||
|
return 4 u - 2 u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testUnary() -> 13
|
||||||
|
// testUnaryWithParens() -> 13
|
||||||
|
// testBinary() -> 200
|
@ -0,0 +1,16 @@
|
|||||||
|
function not(address a) pure suffix returns (bytes20) {
|
||||||
|
return ~bytes20(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function notMin() public pure returns (bytes20) {
|
||||||
|
return 0x0000000000000000000000000000000000000000 not;
|
||||||
|
}
|
||||||
|
|
||||||
|
function notMax() public pure returns (bytes20) {
|
||||||
|
return 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF not;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// notMin() -> 0xffffffffffffffffffffffffffffffffffffffff000000000000000000000000
|
||||||
|
// notMax() -> 0x0000000000000000000000000000000000000000
|
@ -0,0 +1,16 @@
|
|||||||
|
function not(bool a) pure suffix returns (bool) {
|
||||||
|
return !a;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function notTrue() public pure returns (bool) {
|
||||||
|
return true not;
|
||||||
|
}
|
||||||
|
|
||||||
|
function notFalse() public pure returns (bool) {
|
||||||
|
return false not;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// notTrue() -> false
|
||||||
|
// notFalse() -> true
|
@ -0,0 +1,31 @@
|
|||||||
|
function length(bytes memory value) pure suffix returns (uint) {
|
||||||
|
return value.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function empty() public pure returns (uint) {
|
||||||
|
return "" length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function short() public pure returns (uint) {
|
||||||
|
return 'abcd' length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function long() public pure returns (uint) {
|
||||||
|
return 'abcdefghijklmnop abcdefghijklmnop' length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hex_() public pure returns (uint) {
|
||||||
|
return hex'0123456789abcdef' length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unicode_() public pure returns (uint) {
|
||||||
|
return unicode"😃" length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// empty() -> 0
|
||||||
|
// short() -> 4
|
||||||
|
// long() -> 33
|
||||||
|
// hex_() -> 8
|
||||||
|
// unicode_() -> 4
|
@ -0,0 +1,40 @@
|
|||||||
|
function half(int value) pure suffix returns (int) { return value / 2; }
|
||||||
|
function half128(uint128 value) pure suffix returns (uint128) { return value / 2; }
|
||||||
|
function half64s(int64 value) pure suffix returns (int64) { return value / 2; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function zero() public pure returns (int) {
|
||||||
|
return 0 half + int128(0 half128) + 0 half64s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function two() public pure returns (int) {
|
||||||
|
return 2 half + int128(2 half128) + 2 half64s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function negative() public pure returns (int) {
|
||||||
|
return
|
||||||
|
-2 half +
|
||||||
|
-int128(2 half128) +
|
||||||
|
-2 half64s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function max() public pure returns (int) {
|
||||||
|
return
|
||||||
|
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff half +
|
||||||
|
int128(0xffffffffffffffffffffffffffffffff half128) +
|
||||||
|
0x7fffffffffffffff half64s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withDecimals() public pure returns (int) {
|
||||||
|
return
|
||||||
|
2.0 half +
|
||||||
|
int128(0.0004e5 half128) +
|
||||||
|
80000e-2 half64s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// zero() -> 0
|
||||||
|
// two() -> 3
|
||||||
|
// negative() -> -3
|
||||||
|
// max() -> 0x4000000000000000000000000000000080000000000000003ffffffffffffffd
|
||||||
|
// withDecimals() -> 421
|
@ -0,0 +1,21 @@
|
|||||||
|
function suffix(uint x) pure suffix returns (bool) {
|
||||||
|
return x < 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
bool public suffixed1 = 1 suffix ? 2 suffix : 3 suffix ? 4 suffix : 5 suffix;
|
||||||
|
bool public suffixed2 = 1 suffix ? 2 suffix : (3 suffix ? 4 suffix : 5 suffix);
|
||||||
|
bool public suffixed3 = (1 suffix ? 2 suffix : 3 suffix) ? 4 suffix : 5 suffix;
|
||||||
|
|
||||||
|
bool public bare1 = true ? true : false ? false : false;
|
||||||
|
bool public bare2 = true ? true : (false ? false : false);
|
||||||
|
bool public bare3 = (true ? true : false) ? false : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// suffixed1() -> true
|
||||||
|
// suffixed2() -> true
|
||||||
|
// suffixed3() -> false
|
||||||
|
// bare1() -> true
|
||||||
|
// bare2() -> true
|
||||||
|
// bare3() -> false
|
@ -0,0 +1,117 @@
|
|||||||
|
function str(uint) pure suffix returns (bytes memory) {
|
||||||
|
return "abc";
|
||||||
|
}
|
||||||
|
|
||||||
|
function len(bytes memory b) pure suffix returns (uint) {
|
||||||
|
return b.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hash(bytes memory input) pure suffix returns (bytes32) {
|
||||||
|
return keccak256(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
function iszero(uint x) pure suffix returns (bool) {
|
||||||
|
return x == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract D {
|
||||||
|
event Event(bytes, uint);
|
||||||
|
error Err(bytes, uint);
|
||||||
|
|
||||||
|
uint public counter = "" len;
|
||||||
|
|
||||||
|
constructor(bytes memory) {}
|
||||||
|
|
||||||
|
modifier m(bytes memory s) {
|
||||||
|
counter += s.length;
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
function f(bytes memory b) external payable returns (uint) {
|
||||||
|
return b.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
library L {
|
||||||
|
function add(uint a, uint b) internal pure returns (uint) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C is D(10 str) {
|
||||||
|
constructor() m(42 str) {
|
||||||
|
counter += 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
using L for *;
|
||||||
|
|
||||||
|
function testModifier() m(88 str) m(99 str) external {}
|
||||||
|
|
||||||
|
function testCallOptions() external returns (uint) {
|
||||||
|
return this.f{gas: gasleft() * 10 / "1234567890" len}(1234 str);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNamedArgs() external returns (uint) {
|
||||||
|
return this.f({b: 12345 str});
|
||||||
|
}
|
||||||
|
|
||||||
|
function testEvent() external {
|
||||||
|
emit Event(12 str, "xyzw" len);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testError() external pure {
|
||||||
|
revert Err(12 str, "xyzw" len);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testMemoryAllocation() external pure returns (uint) {
|
||||||
|
return new uint[]("12345" len).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNewContract() external returns (uint) {
|
||||||
|
return new D{salt: "123" hash}(100 str).f(1234567 str);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAttachedCall() external pure returns (uint) {
|
||||||
|
return ("abc" len).add(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCondition() external pure returns (uint) {
|
||||||
|
if (0 iszero)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAssert() external pure {
|
||||||
|
assert(0 iszero);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testRequire() external pure {
|
||||||
|
require(0 iszero);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTuple() external pure returns (bool, bool) {
|
||||||
|
return (0 iszero, 1 iszero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// EVMVersion: >=constantinople
|
||||||
|
// ----
|
||||||
|
// counter() -> 13
|
||||||
|
// testModifier() ->
|
||||||
|
// counter() -> 19
|
||||||
|
// testCallOptions() -> 3
|
||||||
|
// testNamedArgs() -> 3
|
||||||
|
// testEvent() ->
|
||||||
|
// ~ emit Event(bytes,uint256): 0x40, 0x04, 0x03, "abc"
|
||||||
|
// testError() -> FAILURE, hex"83e31485", 0x40, 0x04, 0x03, "abc"
|
||||||
|
// testMemoryAllocation() -> 5
|
||||||
|
// testNewContract() -> 3
|
||||||
|
// gas irOptimized: 111878
|
||||||
|
// gas legacy: 185340
|
||||||
|
// gas legacyOptimized: 118889
|
||||||
|
// testAttachedCall() -> 6
|
||||||
|
// testCondition() -> 1
|
||||||
|
// testAssert() ->
|
||||||
|
// testRequire() ->
|
||||||
|
// testTuple() -> 1, 0
|
@ -0,0 +1,33 @@
|
|||||||
|
function stringSuffix(string memory s) pure suffix returns (string memory) { return s; }
|
||||||
|
function bytesSuffix(bytes memory b) pure suffix returns (bytes memory) { return b; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
string public emptyString = "" '' "" "" stringSuffix;
|
||||||
|
bytes public emptyHex = hex"" hex'' hex"" hex"" bytesSuffix;
|
||||||
|
string public emptyUnicode = unicode"" unicode'' unicode"" unicode"" stringSuffix;
|
||||||
|
|
||||||
|
string public string1 = "abcd" "" stringSuffix;
|
||||||
|
string public string2 = "" "efgh" stringSuffix;
|
||||||
|
string public string3 = "abcd" "efgh" stringSuffix;
|
||||||
|
|
||||||
|
bytes public hex1 = hex"9798" hex"" bytesSuffix;
|
||||||
|
bytes public hex2 = hex"" hex"99a0" bytesSuffix;
|
||||||
|
bytes public hex3 = hex"9798" hex"99a0" bytesSuffix;
|
||||||
|
|
||||||
|
string public unicode1 = unicode"😃" unicode"" stringSuffix;
|
||||||
|
string public unicode2 = unicode"" unicode"😃" stringSuffix;
|
||||||
|
string public unicode3 = unicode"😃" unicode"😃" stringSuffix;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// emptyString() -> 0x20, 0
|
||||||
|
// emptyHex() -> 0x20, 0
|
||||||
|
// emptyUnicode() -> 0x20, 0
|
||||||
|
// string1() -> 0x20, 4, "abcd"
|
||||||
|
// string2() -> 0x20, 4, "efgh"
|
||||||
|
// string3() -> 0x20, 8, "abcdefgh"
|
||||||
|
// hex1() -> 0x20, 2, 0x9798000000000000000000000000000000000000000000000000000000000000
|
||||||
|
// hex2() -> 0x20, 2, 0x99a0000000000000000000000000000000000000000000000000000000000000
|
||||||
|
// hex3() -> 0x20, 4, 0x979899a000000000000000000000000000000000000000000000000000000000
|
||||||
|
// unicode1() -> 0x20, 4, "\xf0\x9f\x98\x83"
|
||||||
|
// unicode2() -> 0x20, 4, "\xf0\x9f\x98\x83"
|
||||||
|
// unicode3() -> 0x20, 8, "\xf0\x9f\x98\x83\xf0\x9f\x98\x83"
|
@ -0,0 +1,26 @@
|
|||||||
|
function length(string memory value) pure suffix returns (uint) {
|
||||||
|
return bytes(value).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function empty() public pure returns (uint) {
|
||||||
|
return "" length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function short() public pure returns (uint) {
|
||||||
|
return 'abcd' length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function long() public pure returns (uint) {
|
||||||
|
return 'abcdefghijklmnop abcdefghijklmnop' length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function unicode_() public pure returns (uint) {
|
||||||
|
return unicode"😃" length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// empty() -> 0
|
||||||
|
// short() -> 4
|
||||||
|
// long() -> 33
|
||||||
|
// unicode_() -> 4
|
@ -0,0 +1,34 @@
|
|||||||
|
type UncheckedCounter is uint;
|
||||||
|
|
||||||
|
using {
|
||||||
|
add as +,
|
||||||
|
lt as <
|
||||||
|
} for UncheckedCounter global;
|
||||||
|
|
||||||
|
function add(UncheckedCounter x, UncheckedCounter y) pure returns (UncheckedCounter) {
|
||||||
|
unchecked {
|
||||||
|
return UncheckedCounter.wrap(UncheckedCounter.unwrap(x) + UncheckedCounter.unwrap(y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function lt(UncheckedCounter x, UncheckedCounter y) pure returns (bool) {
|
||||||
|
return UncheckedCounter.unwrap(x) < UncheckedCounter.unwrap(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cycles(uint c) pure suffix returns (UncheckedCounter) {
|
||||||
|
return UncheckedCounter.wrap(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
uint public total = 0;
|
||||||
|
|
||||||
|
function testCounter() public returns (uint) {
|
||||||
|
for (UncheckedCounter i = 20 cycles; i < 23 cycles; i = i + 1 cycles)
|
||||||
|
total += UncheckedCounter.unwrap(i);
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testCounter() -> 63
|
||||||
|
// total() -> 63
|
@ -0,0 +1,20 @@
|
|||||||
|
function uncheckedSuffix(uint8 x) pure suffix returns (uint8) {
|
||||||
|
unchecked {
|
||||||
|
return x + 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function testUncheckedSuffix() public pure returns (uint8) {
|
||||||
|
return 250 uncheckedSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
function testUncheckedSuffixInUncheckedBlock() public pure returns (uint8) {
|
||||||
|
unchecked {
|
||||||
|
return 250 uncheckedSuffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// testUncheckedSuffix() -> 4
|
||||||
|
// testUncheckedSuffixInUncheckedBlock() -> 4
|
@ -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): Integer 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,5 @@
|
|||||||
|
function suffix(uint x) pure suffix returns (uint) { return x; }
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
uint immutable a = 1 suffix;
|
||||||
|
}
|
@ -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,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 (int8) {}
|
||||||
|
function uSuffix(uint16, uint) pure suffix returns (int16) {}
|
||||||
|
|
||||||
|
function iSuffix(int8, uint) pure suffix returns (int24) {}
|
||||||
|
function iSuffix(int16, uint) pure suffix returns (int32) {}
|
||||||
|
|
||||||
|
function iuSuffix(uint8, uint) pure suffix returns (int40) {}
|
||||||
|
function iuSuffix(int8, uint) pure suffix returns (int48) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
int16 a = 1.024 uSuffix;
|
||||||
|
int32 b = 1.024 iSuffix;
|
||||||
|
|
||||||
|
int16 c = -1.024 uSuffix;
|
||||||
|
int32 d = -1.024 iSuffix;
|
||||||
|
|
||||||
|
int40 e = 2.55 iuSuffix;
|
||||||
|
int40 f = -2.55 iuSuffix;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
function iuSuffix(uint8, uint) pure suffix returns (uint) {}
|
||||||
|
function iuSuffix(int8, uint) pure suffix returns (uint) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
uint a = 1.27 iuSuffix;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 4487: (153-161): No unique declaration found after argument-dependent lookup.
|
@ -0,0 +1,8 @@
|
|||||||
|
function uSuffix(uint8, uint) pure suffix returns (uint) {}
|
||||||
|
function uSuffix(uint16, uint) pure suffix returns (uint) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
uint a = 1.27 uSuffix;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 4487: (153-160): 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,10 @@
|
|||||||
|
function suffix256(uint) pure suffix returns (uint) {}
|
||||||
|
function suffix256(uint, uint) pure suffix returns (int) {}
|
||||||
|
|
||||||
|
function suffix8(uint) pure suffix returns (uint8) {}
|
||||||
|
function suffix8(uint8, uint) pure suffix returns (int8) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
int a = 1.1 suffix256;
|
||||||
|
uint8 b = 1024 suffix8;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
function suffix(uint) pure suffix returns (int) {}
|
||||||
|
function suffix(uint, uint) pure suffix returns (int) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
int a = 1 suffix;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 4487: (171-177): No unique declaration found after argument-dependent lookup.
|
@ -0,0 +1,19 @@
|
|||||||
|
function uSuffix(uint8) pure suffix returns (int8) {}
|
||||||
|
function uSuffix(uint16) pure suffix returns (int16) {}
|
||||||
|
|
||||||
|
function iSuffix(int8) pure suffix returns (int24) {}
|
||||||
|
function iSuffix(int16) pure suffix returns (int32) {}
|
||||||
|
|
||||||
|
function iuSuffix(uint8) pure suffix returns (int40) {}
|
||||||
|
function iuSuffix(int8) pure suffix returns (int48) {}
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
int16 a = 1024 uSuffix;
|
||||||
|
int32 b = 1024 iSuffix;
|
||||||
|
|
||||||
|
int16 c = -1024 uSuffix;
|
||||||
|
int32 d = -1024 iSuffix;
|
||||||
|
|
||||||
|
int40 e = 255 iuSuffix;
|
||||||
|
int40 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.
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user