Skip to content

Commit

Permalink
Merge pull request ethereum#14723 from ethereum/fixImportAstInlineAss…
Browse files Browse the repository at this point in the history
…emblyEmptyValueVariable

Fix error when using importing ast with a empty `let` variable declaration
  • Loading branch information
ekpyron authored Dec 12, 2023
2 parents 3d3765c + 8f051dd commit cdf2f5e
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Compiler Features:


Bugfixes:
* AST import: Fix bug when importing inline assembly with empty ``let`` variable declaration.


### 0.8.23 (2023-11-08)
Expand Down
5 changes: 4 additions & 1 deletion libyul/AsmJsonImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ VariableDeclaration AsmJsonImporter::createVariableDeclaration(Json::Value const
auto varDec = createAsmNode<VariableDeclaration>(_node);
for (auto const& var: member(_node, "variables"))
varDec.variables.emplace_back(createTypedName(var));
varDec.value = std::make_unique<Expression>(createExpression(member(_node, "value")));

if (_node.isMember("value"))
varDec.value = std::make_unique<Expression>(createExpression(member(_node, "value")));

return varDec;
}

Expand Down
108 changes: 108 additions & 0 deletions test/libsolidity/ASTJSON/assembly/empty_let_variable_declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
6
]
},
"id": 7,
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"canonicalName": "C",
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 6,
"linearizedBaseContracts":
[
6
],
"name": "C",
"nameLocation": "9:1:1",
"nodeType": "ContractDefinition",
"nodes":
[
{
"body":
{
"id": 4,
"nodeType": "Block",
"src": "39:30:1",
"statements":
[
{
"AST":
{
"nativeSrc": "52:14:1",
"nodeType": "YulBlock",
"src": "52:14:1",
"statements":
[
{
"nativeSrc": "57:5:1",
"nodeType": "YulVariableDeclaration",
"src": "57:5:1",
"variables":
[
{
"name": "x",
"nativeSrc": "61:1:1",
"nodeType": "YulTypedName",
"src": "61:1:1",
"type": ""
}
]
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",
"src": "43:23:1"
}
]
},
"functionSelector": "26121ff0",
"id": 5,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "f",
"nameLocation": "23:1:1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "24:2:1"
},
"returnParameters":
{
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "39:0:1"
},
"scope": 6,
"src": "14:55:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
}
],
"scope": 7,
"src": "0:71:1",
"usedErrors": [],
"usedEvents": []
}
],
"src": "0:72:1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
contract C {
function f() public pure {
assembly {
let x
}
}
}
// ----
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"absolutePath": "a",
"id": 7,
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"id": 6,
"name": "C",
"nameLocation": "9:1:1",
"nodeType": "ContractDefinition",
"nodes":
[
{
"body":
{
"id": 4,
"nodeType": "Block",
"src": "39:30:1",
"statements":
[
{
"AST":
{
"nativeSrc": "52:14:1",
"nodeType": "YulBlock",
"src": "52:14:1",
"statements":
[
{
"nativeSrc": "57:5:1",
"nodeType": "YulVariableDeclaration",
"src": "57:5:1",
"variables":
[
{
"name": "x",
"nativeSrc": "61:1:1",
"nodeType": "YulTypedName",
"src": "61:1:1",
"type": ""
}
]
}
]
},
"evmVersion": %EVMVERSION%,
"externalReferences": [],
"id": 3,
"nodeType": "InlineAssembly",
"src": "43:23:1"
}
]
},
"id": 5,
"implemented": true,
"kind": "function",
"modifiers": [],
"name": "f",
"nameLocation": "23:1:1",
"nodeType": "FunctionDefinition",
"parameters":
{
"id": 1,
"nodeType": "ParameterList",
"parameters": [],
"src": "24:2:1"
},
"returnParameters":
{
"id": 2,
"nodeType": "ParameterList",
"parameters": [],
"src": "39:0:1"
},
"src": "14:55:1",
"stateMutability": "pure",
"virtual": false,
"visibility": "public"
}
],
"src": "0:71:1",
"usedErrors": [],
"usedEvents": []
}
],
"src": "0:72:1"
}

0 comments on commit cdf2f5e

Please sign in to comment.