Merge pull request #12696 from ethereum/unreliableAstJsonTests

Fix unreliable ASTJson tests
This commit is contained in:
chriseth 2022-03-14 15:02:54 +01:00 committed by GitHub
commit 9ef590cc9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 781 additions and 247 deletions

View File

@ -423,18 +423,19 @@
"isPure": true,
"lValueRequested": false,
"nodeType": "ElementaryTypeNameExpression",
"src": "239:7:1",
"src": "239:8:1",
"typeDescriptions":
{
"typeIdentifier": "t_type$_t_address_$",
"typeString": "type(address)"
"typeIdentifier": "t_type$_t_address_payable_$",
"typeString": "type(address payable)"
},
"typeName":
{
"id": 31,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "239:7:1",
"src": "239:8:1",
"stateMutability": "payable",
"typeDescriptions": {}
}
},
@ -450,8 +451,8 @@
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_address",
"typeString": "address"
"typeIdentifier": "t_address_payable",
"typeString": "address payable"
}
},
"src": "232:17:1",

View File

@ -4,7 +4,7 @@ contract C {
address payable a = m[arg];
r = arg;
address c = address(this);
m[c] = address(0);
m[c] = payable(0);
}
}

View File

@ -268,14 +268,15 @@
{
"id": 32,
"nodeType": "ElementaryTypeNameExpression",
"src": "239:7:1",
"src": "239:8:1",
"typeDescriptions": {},
"typeName":
{
"id": 31,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "239:7:1",
"src": "239:8:1",
"stateMutability": "payable",
"typeDescriptions": {}
}
},

View File

@ -17,6 +17,7 @@
"canonicalName": "C",
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 8,
"linearizedBaseContracts":
[
@ -32,21 +33,21 @@
{
"id": 6,
"nodeType": "Block",
"src": "57:97:1",
"src": "57:95:1",
"statements":
[
{
"AST":
{
"nodeType": "YulBlock",
"src": "72:78:1",
"src": "72:76:1",
"statements":
[
{
"body":
{
"nodeType": "YulBlock",
"src": "94:50:1",
"src": "94:35:1",
"statements":
[
{
@ -59,43 +60,53 @@
"name": "f2",
"nodeType": "YulFunctionDefinition",
"src": "104:17:1"
},
{
"nodeType": "YulAssignment",
"src": "130:6:1",
"value":
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "135:1:1",
"type": "",
"value": "2"
},
"variableNames":
[
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "130:1:1"
}
]
}
]
},
"name": "f1",
"nodeType": "YulFunctionDefinition",
"src": "80:64:1"
"src": "80:49:1"
},
{
"nodeType": "YulAssignment",
"src": "136:6:1",
"value":
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "141:1:1",
"type": "",
"value": "2"
},
"variableNames":
[
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "136:1:1"
}
]
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"externalReferences":
[
{
"declaration": 3,
"isOffset": false,
"isSlot": false,
"src": "136:1:1",
"valueSize": 1
}
],
"id": 5,
"nodeType": "InlineAssembly",
"src": "63:87:1"
"src": "63:85:1"
}
]
},
"functionSelector": "26121ff0",
"id": 7,
"implemented": true,
"kind": "function",
@ -127,14 +138,22 @@
"src": "49:6:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {},
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
},
"typeName":
{
"id": 2,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "49:4:1",
"typeDescriptions": {}
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
"typeString": "uint256"
}
},
"visibility": "internal"
}
@ -142,16 +161,16 @@
"src": "48:8:1"
},
"scope": 8,
"src": "15:139:1",
"src": "15:137:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
}
],
"scope": 9,
"src": "0:156:1",
"src": "0:154:1",
"usedErrors": []
}
],
"src": "0:157:1"
"src": "0:155:1"
}

View File

@ -3,8 +3,8 @@ contract C {
assembly {
function f1() {
function f2() { }
x := 2
}
x := 2
}
}
}

View File

@ -20,21 +20,21 @@
{
"id": 6,
"nodeType": "Block",
"src": "57:97:1",
"src": "57:95:1",
"statements":
[
{
"AST":
{
"nodeType": "YulBlock",
"src": "72:78:1",
"src": "72:76:1",
"statements":
[
{
"body":
{
"nodeType": "YulBlock",
"src": "94:50:1",
"src": "94:35:1",
"statements":
[
{
@ -47,32 +47,32 @@
"name": "f2",
"nodeType": "YulFunctionDefinition",
"src": "104:17:1"
},
{
"nodeType": "YulAssignment",
"src": "130:6:1",
"value":
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "135:1:1",
"type": "",
"value": "2"
},
"variableNames":
[
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "130:1:1"
}
]
}
]
},
"name": "f1",
"nodeType": "YulFunctionDefinition",
"src": "80:64:1"
"src": "80:49:1"
},
{
"nodeType": "YulAssignment",
"src": "136:6:1",
"value":
{
"kind": "number",
"nodeType": "YulLiteral",
"src": "141:1:1",
"type": "",
"value": "2"
},
"variableNames":
[
{
"name": "x",
"nodeType": "YulIdentifier",
"src": "136:1:1"
}
]
}
]
},
@ -80,7 +80,7 @@
"externalReferences": [],
"id": 5,
"nodeType": "InlineAssembly",
"src": "63:87:1"
"src": "63:85:1"
}
]
},
@ -128,15 +128,15 @@
],
"src": "48:8:1"
},
"src": "15:139:1",
"src": "15:137:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
}
],
"src": "0:156:1",
"src": "0:154:1",
"usedErrors": []
}
],
"src": "0:157:1"
"src": "0:155:1"
}

View File

@ -17,6 +17,7 @@
"canonicalName": "C",
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 6,
"linearizedBaseContracts":
[
@ -56,7 +57,7 @@
"variables":
[
{
"name": "f",
"name": "v",
"nodeType": "YulTypedName",
"src": "79:1:1",
"type": ""
@ -87,7 +88,7 @@
"variableNames":
[
{
"name": "f",
"name": "v",
"nodeType": "YulIdentifier",
"src": "141:1:1"
}
@ -127,7 +128,7 @@
"variableNames":
[
{
"name": "f",
"name": "v",
"nodeType": "YulIdentifier",
"src": "172:1:1"
}
@ -158,29 +159,14 @@
]
},
"evmVersion": %EVMVERSION%,
"externalReferences":
[
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "141:1:1",
"valueSize": 18446744073709551615
},
{
"declaration": 5,
"isOffset": false,
"isSlot": false,
"src": "172:1:1",
"valueSize": 18446744073709551615
}
],
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",
"src": "52:138:1"
}
]
},
"functionSelector": "26121ff0",
"id": 5,
"implemented": true,
"kind": "function",

View File

@ -1,10 +1,10 @@
contract C {
function f() pure public {
assembly {
let f := 0
let v := 0
switch calldatasize()
case 0 { f := 1 }
default { f := 2 }
case 0 { v := 1 }
default { v := 2 }
}
}
}

View File

@ -44,7 +44,7 @@
"variables":
[
{
"name": "f",
"name": "v",
"nodeType": "YulTypedName",
"src": "79:1:1",
"type": ""
@ -75,7 +75,7 @@
"variableNames":
[
{
"name": "f",
"name": "v",
"nodeType": "YulIdentifier",
"src": "141:1:1"
}
@ -115,7 +115,7 @@
"variableNames":
[
{
"name": "f",
"name": "v",
"nodeType": "YulIdentifier",
"src": "172:1:1"
}

View File

@ -0,0 +1,16 @@
function g() public;
interface I {
struct S { S s; }
function f(E storage e) {
error E;
emit E();
++c;
uint calldata c = 123.4;
}
}
// ----
// failAfter: Parsed

View File

@ -0,0 +1,283 @@
{
"absolutePath": "a",
"id": 30,
"nodeType": "SourceUnit",
"nodes":
[
{
"id": 3,
"implemented": false,
"kind": "freeFunction",
"modifiers": [],
"name": "g",
"nameLocation": "9:1:1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "10:2:1"
},
"returnParameters":
{
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "19:0:1"
},
"src": "0:20:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
},
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "interface",
"id": 29,
"name": "I",
"nameLocation": "31:1:1",
"nodeType": "ContractDefinition",
"nodes":
[
{
"id": 7,
"members":
[
{
"constant": false,
"id": 6,
"mutability": "mutable",
"name": "s",
"nameLocation": "52:1:1",
"nodeType": "VariableDeclaration",
"src": "50:3:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {},
"typeName":
{
"id": 5,
"nodeType": "UserDefinedTypeName",
"pathNode":
{
"id": 4,
"name": "S",
"nodeType": "IdentifierPath",
"src": "50:1:1"
},
"src": "50:1:1",
"typeDescriptions": {}
},
"visibility": "internal"
}
],
"name": "S",
"nameLocation": "46:1:1",
"nodeType": "StructDefinition",
"src": "39:17:1",
"visibility": "public"
},
{
"body":
{
"id": 27,
"nodeType": "Block",
"src": "85:88:1",
"statements":
[
{
"assignments":
[
15
],
"declarations":
[
{
"constant": false,
"id": 15,
"mutability": "mutable",
"name": "E",
"nameLocation": "101:1:1",
"nodeType": "VariableDeclaration",
"src": "95:7:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {},
"typeName":
{
"id": 14,
"nodeType": "UserDefinedTypeName",
"pathNode":
{
"id": 13,
"name": "error",
"nodeType": "IdentifierPath",
"src": "95:5:1"
},
"src": "95:5:1",
"typeDescriptions": {}
},
"visibility": "internal"
}
],
"id": 16,
"nodeType": "VariableDeclarationStatement",
"src": "95:7:1"
},
{
"eventCall":
{
"arguments": [],
"expression":
{
"id": 17,
"name": "E",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"src": "117:1:1",
"typeDescriptions": {}
},
"id": 18,
"names": [],
"nodeType": "FunctionCall",
"src": "117:3:1",
"tryCall": false,
"typeDescriptions": {}
},
"id": 19,
"nodeType": "EmitStatement",
"src": "112:8:1"
},
{
"expression":
{
"id": 21,
"nodeType": "UnaryOperation",
"operator": "++",
"prefix": true,
"src": "130:3:1",
"subExpression":
{
"id": 20,
"name": "c",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"src": "132:1:1",
"typeDescriptions": {}
},
"typeDescriptions": {}
},
"id": 22,
"nodeType": "ExpressionStatement",
"src": "130:3:1"
},
{
"assignments":
[
24
],
"declarations":
[
{
"constant": false,
"id": 24,
"mutability": "mutable",
"name": "c",
"nameLocation": "157:1:1",
"nodeType": "VariableDeclaration",
"src": "143:15:1",
"stateVariable": false,
"storageLocation": "calldata",
"typeDescriptions": {},
"typeName":
{
"id": 23,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "143:4:1",
"typeDescriptions": {}
},
"visibility": "internal"
}
],
"id": 26,
"initialValue":
{
"hexValue": "3132332e34",
"id": 25,
"kind": "number",
"nodeType": "Literal",
"src": "161:5:1",
"typeDescriptions": {},
"value": "123.4"
},
"nodeType": "VariableDeclarationStatement",
"src": "143:23:1"
}
]
},
"id": 28,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "f",
"nameLocation": "70:1:1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 11,
"nodeType": "ParameterList",
"parameters":
[
{
"constant": false,
"id": 10,
"mutability": "mutable",
"name": "e",
"nameLocation": "82:1:1",
"nodeType": "VariableDeclaration",
"src": "72:11:1",
"stateVariable": false,
"storageLocation": "storage",
"typeDescriptions": {},
"typeName":
{
"id": 9,
"nodeType": "UserDefinedTypeName",
"pathNode":
{
"id": 8,
"name": "E",
"nodeType": "IdentifierPath",
"src": "72:1:1"
},
"src": "72:1:1",
"typeDescriptions": {}
},
"visibility": "internal"
}
],
"src": "71:13:1"
},
"returnParameters":
{
"id": 12,
"nodeType": "ParameterList",
"parameters": [],
"src": "85:0:1"
},
"src": "61:112:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"src": "21:154:1",
"usedErrors": []
}
],
"src": "0:176:1"
}

View File

@ -33,7 +33,7 @@
{
"id": 15,
"nodeType": "Block",
"src": "120:2:1",
"src": "127:2:1",
"statements": []
},
"functionSelector": "d6cd4974",
@ -144,7 +144,7 @@
"nameLocation": "-1:-1:-1",
"nodeType": "VariableDeclaration",
"scope": 16,
"src": "79:40:1",
"src": "86:40:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions":
@ -161,7 +161,7 @@
"id": 8,
"nodeType": "ParameterList",
"parameters": [],
"src": "87:2:1"
"src": "94:2:1"
},
"returnParameterTypes":
{
@ -177,7 +177,7 @@
"nameLocation": "-1:-1:-1",
"nodeType": "VariableDeclaration",
"scope": 12,
"src": "113:4:1",
"src": "120:4:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions":
@ -190,7 +190,7 @@
"id": 9,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "113:4:1",
"src": "120:4:1",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
@ -200,9 +200,9 @@
"visibility": "internal"
}
],
"src": "112:6:1"
"src": "119:6:1"
},
"src": "79:40:1",
"src": "86:40:1",
"stateMutability": "view",
"typeDescriptions":
{
@ -214,19 +214,19 @@
"visibility": "internal"
}
],
"src": "78:41:1"
"src": "85:41:1"
},
"scope": 17,
"src": "13:109:1",
"src": "13:116:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"scope": 18,
"src": "0:124:1",
"src": "0:131:1",
"usedErrors": []
}
],
"src": "0:125:1"
"src": "0:132:1"
}

View File

@ -1,3 +1,3 @@
contract C { function f(function() external payable returns (uint) x) returns (function() external view returns (uint)) {} }
contract C { function f(function() external payable returns (uint) x) public returns (function() external view returns (uint)) {} }
// ----

View File

@ -20,7 +20,7 @@
{
"id": 15,
"nodeType": "Block",
"src": "120:2:1",
"src": "127:2:1",
"statements": []
},
"id": 16,
@ -111,7 +111,7 @@
"name": "",
"nameLocation": "-1:-1:-1",
"nodeType": "VariableDeclaration",
"src": "79:40:1",
"src": "86:40:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {},
@ -124,7 +124,7 @@
"id": 8,
"nodeType": "ParameterList",
"parameters": [],
"src": "87:2:1"
"src": "94:2:1"
},
"returnParameterTypes":
{
@ -139,7 +139,7 @@
"name": "",
"nameLocation": "-1:-1:-1",
"nodeType": "VariableDeclaration",
"src": "113:4:1",
"src": "120:4:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {},
@ -148,15 +148,15 @@
"id": 9,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "113:4:1",
"src": "120:4:1",
"typeDescriptions": {}
},
"visibility": "internal"
}
],
"src": "112:6:1"
"src": "119:6:1"
},
"src": "79:40:1",
"src": "86:40:1",
"stateMutability": "view",
"typeDescriptions": {},
"visibility": "external"
@ -164,17 +164,17 @@
"visibility": "internal"
}
],
"src": "78:41:1"
"src": "85:41:1"
},
"src": "13:109:1",
"src": "13:116:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"src": "0:124:1",
"src": "0:131:1",
"usedErrors": []
}
],
"src": "0:125:1"
"src": "0:132:1"
}

View File

@ -4,10 +4,10 @@
{
"C":
[
9
15
]
},
"id": 10,
"id": 16,
"nodeType": "SourceUnit",
"nodes":
[
@ -18,10 +18,10 @@
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 9,
"id": 15,
"linearizedBaseContracts":
[
9
15
],
"name": "C",
"nameLocation": "9:1:1",
@ -31,9 +31,9 @@
{
"body":
{
"id": 7,
"id": 13,
"nodeType": "Block",
"src": "33:30:1",
"src": "33:45:1",
"statements":
[
{
@ -50,7 +50,7 @@
"name": "x",
"nameLocation": "49:1:1",
"nodeType": "VariableDeclaration",
"scope": 7,
"scope": 13,
"src": "35:15:1",
"stateVariable": false,
"storageLocation": "memory",
@ -74,31 +74,131 @@
"visibility": "internal"
}
],
"id": 6,
"id": 12,
"initialValue":
{
"hexValue": "ff",
"id": 5,
"arguments":
[
{
"arguments":
[
{
"hexValue": "ff",
"id": 9,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "hexString",
"lValueRequested": false,
"nodeType": "Literal",
"src": "66:7:1",
"typeDescriptions":
{
"typeIdentifier": "t_stringliteral_8b1a944cf13a9a1c08facb2c9e98623ef3254d2ddb48113885c3e8e97fec8db9",
"typeString": "literal_string hex\"ff\""
}
}
],
"expression":
{
"argumentTypes":
[
{
"typeIdentifier": "t_stringliteral_8b1a944cf13a9a1c08facb2c9e98623ef3254d2ddb48113885c3e8e97fec8db9",
"typeString": "literal_string hex\"ff\""
}
],
"id": 8,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "ElementaryTypeNameExpression",
"src": "60:5:1",
"typeDescriptions":
{
"typeIdentifier": "t_type$_t_bytes_storage_ptr_$",
"typeString": "type(bytes storage pointer)"
},
"typeName":
{
"id": 7,
"name": "bytes",
"nodeType": "ElementaryTypeName",
"src": "60:5:1",
"typeDescriptions": {}
}
},
"id": 10,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "typeConversion",
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "60:14:1",
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_bytes_memory_ptr",
"typeString": "bytes memory"
}
}
],
"expression":
{
"argumentTypes":
[
{
"typeIdentifier": "t_bytes_memory_ptr",
"typeString": "bytes memory"
}
],
"id": 6,
"isConstant": false,
"isLValue": false,
"isPure": true,
"lValueRequested": false,
"nodeType": "ElementaryTypeNameExpression",
"src": "53:6:1",
"typeDescriptions":
{
"typeIdentifier": "t_type$_t_string_storage_ptr_$",
"typeString": "type(string storage pointer)"
},
"typeName":
{
"id": 5,
"name": "string",
"nodeType": "ElementaryTypeName",
"src": "53:6:1",
"typeDescriptions": {}
}
},
"id": 11,
"isConstant": false,
"isLValue": false,
"isPure": true,
"kind": "hexString",
"kind": "typeConversion",
"lValueRequested": false,
"nodeType": "Literal",
"src": "53:7:1",
"names": [],
"nodeType": "FunctionCall",
"src": "53:22:1",
"tryCall": false,
"typeDescriptions":
{
"typeIdentifier": "t_stringliteral_8b1a944cf13a9a1c08facb2c9e98623ef3254d2ddb48113885c3e8e97fec8db9",
"typeString": "literal_string hex\"ff\""
"typeIdentifier": "t_string_memory_ptr",
"typeString": "string memory"
}
},
"nodeType": "VariableDeclarationStatement",
"src": "35:25:1"
"src": "35:40:1"
}
]
},
"functionSelector": "26121ff0",
"id": 8,
"id": 14,
"implemented": true,
"kind": "function",
"modifiers": [],
@ -119,17 +219,17 @@
"parameters": [],
"src": "33:0:1"
},
"scope": 9,
"src": "13:50:1",
"scope": 15,
"src": "13:65:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"scope": 10,
"src": "0:65:1",
"scope": 16,
"src": "0:80:1",
"usedErrors": []
}
],
"src": "0:66:1"
"src": "0:81:1"
}

View File

@ -1,3 +1,3 @@
contract C { function f() public { string memory x = hex"ff"; } }
contract C { function f() public { string memory x = string(bytes(hex"ff")); } }
// ----

View File

@ -1,6 +1,6 @@
{
"absolutePath": "a",
"id": 10,
"id": 16,
"nodeType": "SourceUnit",
"nodes":
[
@ -9,7 +9,7 @@
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"id": 9,
"id": 15,
"name": "C",
"nameLocation": "9:1:1",
"nodeType": "ContractDefinition",
@ -18,9 +18,9 @@
{
"body":
{
"id": 7,
"id": 13,
"nodeType": "Block",
"src": "33:30:1",
"src": "33:45:1",
"statements":
[
{
@ -52,22 +52,74 @@
"visibility": "internal"
}
],
"id": 6,
"id": 12,
"initialValue":
{
"hexValue": "ff",
"id": 5,
"kind": "hexString",
"nodeType": "Literal",
"src": "53:7:1",
"arguments":
[
{
"arguments":
[
{
"hexValue": "ff",
"id": 9,
"kind": "hexString",
"nodeType": "Literal",
"src": "66:7:1",
"typeDescriptions": {}
}
],
"expression":
{
"id": 8,
"nodeType": "ElementaryTypeNameExpression",
"src": "60:5:1",
"typeDescriptions": {},
"typeName":
{
"id": 7,
"name": "bytes",
"nodeType": "ElementaryTypeName",
"src": "60:5:1",
"typeDescriptions": {}
}
},
"id": 10,
"names": [],
"nodeType": "FunctionCall",
"src": "60:14:1",
"tryCall": false,
"typeDescriptions": {}
}
],
"expression":
{
"id": 6,
"nodeType": "ElementaryTypeNameExpression",
"src": "53:6:1",
"typeDescriptions": {},
"typeName":
{
"id": 5,
"name": "string",
"nodeType": "ElementaryTypeName",
"src": "53:6:1",
"typeDescriptions": {}
}
},
"id": 11,
"names": [],
"nodeType": "FunctionCall",
"src": "53:22:1",
"tryCall": false,
"typeDescriptions": {}
},
"nodeType": "VariableDeclarationStatement",
"src": "35:25:1"
"src": "35:40:1"
}
]
},
"id": 8,
"id": 14,
"implemented": true,
"kind": "function",
"modifiers": [],
@ -88,15 +140,15 @@
"parameters": [],
"src": "33:0:1"
},
"src": "13:50:1",
"src": "13:65:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"src": "0:65:1",
"src": "0:80:1",
"usedErrors": []
}
],
"src": "0:66:1"
"src": "0:81:1"
}

View File

@ -6,3 +6,4 @@ contract C is NotExisting.X
}
// ----
// failAfter: Parsed

View File

@ -33,7 +33,7 @@
{
"id": 10,
"nodeType": "Block",
"src": "26:20:1",
"src": "33:20:1",
"statements":
[
{
@ -48,10 +48,10 @@
"id": 4,
"mutability": "mutable",
"name": "x",
"nameLocation": "33:1:1",
"nameLocation": "40:1:1",
"nodeType": "VariableDeclaration",
"scope": 10,
"src": "28:6:1",
"src": "35:6:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions":
@ -64,7 +64,7 @@
"id": 3,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "28:4:1",
"src": "35:4:1",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
@ -85,7 +85,7 @@
"kind": "number",
"lValueRequested": false,
"nodeType": "Literal",
"src": "37:1:1",
"src": "44:1:1",
"typeDescriptions":
{
"typeIdentifier": "t_rational_2_by_1",
@ -94,7 +94,7 @@
"value": "2"
},
"nodeType": "VariableDeclarationStatement",
"src": "28:10:1"
"src": "35:10:1"
},
{
"expression":
@ -107,7 +107,7 @@
"nodeType": "UnaryOperation",
"operator": "++",
"prefix": false,
"src": "40:3:1",
"src": "47:3:1",
"subExpression":
{
"id": 7,
@ -115,7 +115,7 @@
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 4,
"src": "40:1:1",
"src": "47:1:1",
"typeDescriptions":
{
"typeIdentifier": "t_uint256",
@ -130,7 +130,7 @@
},
"id": 9,
"nodeType": "ExpressionStatement",
"src": "40:3:1"
"src": "47:3:1"
}
]
},
@ -154,19 +154,19 @@
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "26:0:1"
"src": "33:0:1"
},
"scope": 12,
"src": "13:33:1",
"src": "13:40:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"scope": 13,
"src": "0:48:1",
"src": "0:55:1",
"usedErrors": []
}
],
"src": "0:49:1"
"src": "0:56:1"
}

View File

@ -1,3 +1,3 @@
contract C { function f() { uint x = 2; x++; } }
contract C { function f() public { uint x = 2; x++; } }
// ----

View File

@ -20,7 +20,7 @@
{
"id": 10,
"nodeType": "Block",
"src": "26:20:1",
"src": "33:20:1",
"statements":
[
{
@ -35,9 +35,9 @@
"id": 4,
"mutability": "mutable",
"name": "x",
"nameLocation": "33:1:1",
"nameLocation": "40:1:1",
"nodeType": "VariableDeclaration",
"src": "28:6:1",
"src": "35:6:1",
"stateVariable": false,
"storageLocation": "default",
"typeDescriptions": {},
@ -46,7 +46,7 @@
"id": 3,
"name": "uint",
"nodeType": "ElementaryTypeName",
"src": "28:4:1",
"src": "35:4:1",
"typeDescriptions": {}
},
"visibility": "internal"
@ -59,12 +59,12 @@
"id": 5,
"kind": "number",
"nodeType": "Literal",
"src": "37:1:1",
"src": "44:1:1",
"typeDescriptions": {},
"value": "2"
},
"nodeType": "VariableDeclarationStatement",
"src": "28:10:1"
"src": "35:10:1"
},
{
"expression":
@ -73,21 +73,21 @@
"nodeType": "UnaryOperation",
"operator": "++",
"prefix": false,
"src": "40:3:1",
"src": "47:3:1",
"subExpression":
{
"id": 7,
"name": "x",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"src": "40:1:1",
"src": "47:1:1",
"typeDescriptions": {}
},
"typeDescriptions": {}
},
"id": 9,
"nodeType": "ExpressionStatement",
"src": "40:3:1"
"src": "47:3:1"
}
]
},
@ -110,17 +110,17 @@
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "26:0:1"
"src": "33:0:1"
},
"src": "13:33:1",
"src": "13:40:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"src": "0:48:1",
"src": "0:55:1",
"usedErrors": []
}
],
"src": "0:49:1"
"src": "0:56:1"
}

View File

@ -39,7 +39,7 @@
{
"id": 8,
"nodeType": "Block",
"src": "24:15:1",
"src": "29:15:1",
"statements":
[
{
@ -54,7 +54,7 @@
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 2,
"src": "33:1:1",
"src": "38:1:1",
"typeDescriptions":
{
"typeIdentifier": "t_function_error_pure$__$returns$__$",
@ -69,7 +69,7 @@
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "33:3:1",
"src": "38:3:1",
"tryCall": false,
"typeDescriptions":
{
@ -79,7 +79,7 @@
},
"id": 7,
"nodeType": "RevertStatement",
"src": "26:10:1"
"src": "31:10:1"
}
]
},
@ -102,11 +102,11 @@
"id": 4,
"nodeType": "ParameterList",
"parameters": [],
"src": "24:0:1"
"src": "29:0:1"
},
"scope": 20,
"src": "11:28:1",
"stateMutability": "nonpayable",
"src": "11:33:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "internal"
},
@ -123,7 +123,7 @@
19
],
"name": "C",
"nameLocation": "49:1:1",
"nameLocation": "54:1:1",
"nodeType": "ContractDefinition",
"nodes":
[
@ -131,23 +131,23 @@
"errorSelector": "2bc80f3a",
"id": 11,
"name": "T",
"nameLocation": "63:1:1",
"nameLocation": "68:1:1",
"nodeType": "ErrorDefinition",
"parameters":
{
"id": 10,
"nodeType": "ParameterList",
"parameters": [],
"src": "64:2:1"
"src": "69:2:1"
},
"src": "57:10:1"
"src": "62:10:1"
},
{
"body":
{
"id": 17,
"nodeType": "Block",
"src": "92:8:1",
"src": "97:8:1",
"statements":
[
{
@ -162,11 +162,11 @@
"nodeType": "Identifier",
"overloadedDeclarations": [],
"referencedDeclaration": 9,
"src": "94:1:1",
"src": "99:1:1",
"typeDescriptions":
{
"typeIdentifier": "t_function_internal_nonpayable$__$returns$__$",
"typeString": "function ()"
"typeIdentifier": "t_function_internal_pure$__$returns$__$",
"typeString": "function () pure"
}
},
"id": 15,
@ -177,7 +177,7 @@
"lValueRequested": false,
"names": [],
"nodeType": "FunctionCall",
"src": "94:3:1",
"src": "99:3:1",
"tryCall": false,
"typeDescriptions":
{
@ -187,7 +187,7 @@
},
"id": 16,
"nodeType": "ExpressionStatement",
"src": "94:3:1"
"src": "99:3:1"
}
]
},
@ -197,31 +197,31 @@
"kind": "function",
"modifiers": [],
"name": "h",
"nameLocation": "81:1:1",
"nameLocation": "86:1:1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 12,
"nodeType": "ParameterList",
"parameters": [],
"src": "82:2:1"
"src": "87:2:1"
},
"returnParameters":
{
"id": 13,
"nodeType": "ParameterList",
"parameters": [],
"src": "92:0:1"
"src": "97:0:1"
},
"scope": 19,
"src": "72:28:1",
"src": "77:28:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"scope": 20,
"src": "40:62:1",
"src": "45:62:1",
"usedErrors":
[
2,
@ -229,5 +229,5 @@
]
}
],
"src": "0:103:1"
"src": "0:108:1"
}

View File

@ -1,5 +1,5 @@
error X();
function f() { revert X(); }
function f() pure { revert X(); }
contract C {
error T();
function h() public { f(); }

View File

@ -23,7 +23,7 @@
{
"id": 8,
"nodeType": "Block",
"src": "24:15:1",
"src": "29:15:1",
"statements":
[
{
@ -36,19 +36,19 @@
"name": "X",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"src": "33:1:1",
"src": "38:1:1",
"typeDescriptions": {}
},
"id": 6,
"names": [],
"nodeType": "FunctionCall",
"src": "33:3:1",
"src": "38:3:1",
"tryCall": false,
"typeDescriptions": {}
},
"id": 7,
"nodeType": "RevertStatement",
"src": "26:10:1"
"src": "31:10:1"
}
]
},
@ -71,10 +71,10 @@
"id": 4,
"nodeType": "ParameterList",
"parameters": [],
"src": "24:0:1"
"src": "29:0:1"
},
"src": "11:28:1",
"stateMutability": "nonpayable",
"src": "11:33:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "internal"
},
@ -85,30 +85,30 @@
"contractKind": "contract",
"id": 19,
"name": "C",
"nameLocation": "49:1:1",
"nameLocation": "54:1:1",
"nodeType": "ContractDefinition",
"nodes":
[
{
"id": 11,
"name": "T",
"nameLocation": "63:1:1",
"nameLocation": "68:1:1",
"nodeType": "ErrorDefinition",
"parameters":
{
"id": 10,
"nodeType": "ParameterList",
"parameters": [],
"src": "64:2:1"
"src": "69:2:1"
},
"src": "57:10:1"
"src": "62:10:1"
},
{
"body":
{
"id": 17,
"nodeType": "Block",
"src": "92:8:1",
"src": "97:8:1",
"statements":
[
{
@ -121,19 +121,19 @@
"name": "f",
"nodeType": "Identifier",
"overloadedDeclarations": [],
"src": "94:1:1",
"src": "99:1:1",
"typeDescriptions": {}
},
"id": 15,
"names": [],
"nodeType": "FunctionCall",
"src": "94:3:1",
"src": "99:3:1",
"tryCall": false,
"typeDescriptions": {}
},
"id": 16,
"nodeType": "ExpressionStatement",
"src": "94:3:1"
"src": "99:3:1"
}
]
},
@ -142,31 +142,31 @@
"kind": "function",
"modifiers": [],
"name": "h",
"nameLocation": "81:1:1",
"nameLocation": "86:1:1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 12,
"nodeType": "ParameterList",
"parameters": [],
"src": "82:2:1"
"src": "87:2:1"
},
"returnParameters":
{
"id": 13,
"nodeType": "ParameterList",
"parameters": [],
"src": "92:0:1"
"src": "97:0:1"
},
"src": "72:28:1",
"src": "77:28:1",
"stateMutability": "nonpayable",
"virtual": false,
"visibility": "public"
}
],
"src": "40:62:1",
"src": "45:62:1",
"usedErrors": []
}
],
"src": "0:103:1"
"src": "0:108:1"
}

View File

@ -27,6 +27,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/throw_exception.hpp>
@ -49,6 +50,30 @@ namespace
string const sourceDelimiter("==== Source: ");
string compilerStateToString(CompilerStack::State _state)
{
switch (_state)
{
case CompilerStack::State::Empty: return "Empty";
case CompilerStack::State::SourcesSet: return "SourcesSet";
case CompilerStack::State::Parsed: return "Parsed";
case CompilerStack::State::ParsedAndImported: return "ParsedAndImported";
case CompilerStack::State::AnalysisPerformed: return "AnalysisPerformed";
case CompilerStack::State::CompilationSuccessful: return "CompilationSuccessful";
}
soltestAssert(false, "Unexpected value of state parameter");
}
CompilerStack::State stringToCompilerState(const string& _state)
{
for (unsigned int i = CompilerStack::State::Empty; i <= CompilerStack::State::CompilationSuccessful; ++i)
{
if (_state == compilerStateToString(CompilerStack::State(i)))
return CompilerStack::State(i);
}
BOOST_THROW_EXCEPTION(runtime_error("Unsupported compiler state (" + _state + ") in test contract file"));
}
void replaceVersionWithTag(string& _input)
{
boost::algorithm::replace_all(
@ -69,20 +94,30 @@ void replaceTagWithVersion(string& _input)
}
ASTJSONTest::ASTJSONTest(string const& _filename)
void ASTJSONTest::generateTestVariants(string const& _filename)
{
if (!boost::algorithm::ends_with(_filename, ".sol"))
BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\"."));
string_view baseName = _filename;
baseName.remove_suffix(4);
m_variants = {
TestVariant(baseName, CompilerStack::State::Parsed),
TestVariant(baseName, CompilerStack::State::AnalysisPerformed),
const std::vector<CompilerStack::State> variantCompileStates = {
CompilerStack::State::Parsed,
CompilerStack::State::AnalysisPerformed
};
for (const auto state: variantCompileStates)
{
auto variant = TestVariant(baseName, state);
if (boost::filesystem::exists(variant.astFilename()))
{
variant.expectation = readFileAsString(variant.astFilename());
boost::replace_all(variant.expectation, "\r\n", "\n");
m_variants.push_back(variant);
}
}
}
void ASTJSONTest::fillSources(string const& _filename)
{
ifstream file(_filename);
if (!file)
BOOST_THROW_EXCEPTION(runtime_error("Cannot open test contract: \"" + _filename + "\"."));
@ -92,6 +127,7 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
string source;
string line;
string const delimiter("// ----");
string const failMarker("// failAfter:");
while (getline(file, line))
{
if (boost::algorithm::starts_with(line, sourceDelimiter))
@ -105,20 +141,55 @@ ASTJSONTest::ASTJSONTest(string const& _filename)
);
source = string();
}
else if (boost::algorithm::starts_with(line, failMarker))
{
string state = line.substr(failMarker.size());
boost::algorithm::trim(state);
if (m_expectedFailAfter.has_value())
BOOST_THROW_EXCEPTION(runtime_error("Duplicated \"failAfter\" directive"));
m_expectedFailAfter = stringToCompilerState(state);
}
else if (!line.empty() && !boost::algorithm::starts_with(line, delimiter))
source += line + "\n";
}
m_sources.emplace_back(sourceName.empty() ? "a" : sourceName, source);
file.close();
}
for (TestVariant& variant: m_variants)
void ASTJSONTest::validateTestConfiguration() const
{
if (m_variants.empty())
BOOST_THROW_EXCEPTION(runtime_error("No file with expected result found."));
if (m_expectedFailAfter.has_value())
{
variant.expectation = readFileAsString(variant.astFilename());
boost::replace_all(variant.expectation, "\r\n", "\n");
auto unexpectedTestVariant = std::find_if(
m_variants.begin(), m_variants.end(),
[failAfter = m_expectedFailAfter](TestVariant v) { return v.stopAfter > failAfter; }
);
if (unexpectedTestVariant != m_variants.end())
BOOST_THROW_EXCEPTION(
runtime_error(
string("Unexpected JSON file: ") + unexpectedTestVariant->astFilename() +
" in \"failAfter: " +
compilerStateToString(m_expectedFailAfter.value()) + "\" scenario."
)
);
}
}
ASTJSONTest::ASTJSONTest(string const& _filename)
{
if (!boost::algorithm::ends_with(_filename, ".sol"))
BOOST_THROW_EXCEPTION(runtime_error("Invalid test contract file name: \"" + _filename + "\"."));
generateTestVariants(_filename);
fillSources(_filename);
validateTestConfiguration();
}
TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
{
CompilerStack c;
@ -141,13 +212,12 @@ TestCase::TestResult ASTJSONTest::run(ostream& _stream, string const& _linePrefi
if (!c.parseAndAnalyze(variant.stopAfter))
{
// Ignore non-fatal analysis errors, we only want to export.
if (c.state() > CompilerStack::State::Parsed)
continue;
SourceReferenceFormatter formatter(_stream, c, _formatted, false);
formatter.printErrorInformation(c.errors());
return TestResult::FatalError;
if (!m_expectedFailAfter.has_value() || m_expectedFailAfter.value() + 1 != c.state())
{
SourceReferenceFormatter formatter(_stream, c, _formatted, false);
formatter.printErrorInformation(c.errors());
return TestResult::FatalError;
}
}
resultsMatch = resultsMatch && runTest(

View File

@ -89,7 +89,12 @@ private:
std::string const& _variant
) const;
void generateTestVariants(std::string const& _filename);
void fillSources(std::string const& _filename);
void validateTestConfiguration() const;
std::vector<TestVariant> m_variants;
std::optional<CompilerStack::State> m_expectedFailAfter;
std::vector<std::pair<std::string, std::string>> m_sources;
};