Skip to content

Commit d54a35c

Browse files
Resolve identifiers in assembly blocks to locally imported symbols (#1424)
Fix #1421 Even if the imported symbol cannot be resolved, the identifier should still resolve to the local definition in the import statement, so that code in assembly blocks is consistent with normal Solidity code. --------- Co-authored-by: Beta Ziliani <beta.ziliani@gmail.com>
1 parent 7a101a7 commit d54a35c

File tree

16 files changed

+180
-31
lines changed

16 files changed

+180
-31
lines changed

.changeset/eleven-parents-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomicfoundation/slang": patch
3+
---
4+
5+
Resolve identifiers in assembly blocks to locally imported symbols

crates/solidity/inputs/language/bindings/rules.msgb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,15 @@ inherit .star_extension
260260
node @symbol.import
261261
edge @symbol.import -> @path.import
262262

263-
node @symbol.yul_def
264-
edge @import.yul_defs -> @symbol.yul_def
265-
node @symbol.yul_import
266-
edge @symbol.yul_import -> @import.yul_path
263+
edge @import.yul_defs -> @symbol.def
264+
edge @symbol.import -> @import.yul_path
267265
}
268266

269267
@symbol [ImportDeconstructionSymbol @name name: [Identifier] .] {
270268
attr (@symbol.def) node_definition = @name
271269
attr (@symbol.def) definiens_node = @symbol
272270
attr (@symbol.import) node_reference = @name
273271
edge @symbol.def -> @symbol.import
274-
275-
attr (@symbol.yul_def) pop_symbol = (source-text @name)
276-
attr (@symbol.yul_import) push_symbol = (source-text @name)
277-
edge @symbol.yul_def -> @symbol.yul_import
278272
}
279273

280274
@symbol [ImportDeconstructionSymbol
@@ -285,10 +279,6 @@ inherit .star_extension
285279
attr (@symbol.def) definiens_node = @symbol
286280
attr (@symbol.import) node_reference = @name
287281
edge @symbol.def -> @symbol.import
288-
289-
attr (@symbol.yul_def) pop_symbol = (source-text @alias)
290-
attr (@symbol.yul_import) push_symbol = (source-text @name)
291-
edge @symbol.yul_def -> @symbol.yul_import
292282
}
293283

294284

crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity/outputs/cargo/tests/src/binder/generated/yul.rs

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity/outputs/cargo/tests/src/bindings/bindings_output/generated/yul.rs

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.
2+
3+
reference `FOO` at main.sol:6:26 failed to resolve in new binder
4+
5+
Definitions and/or references from binding graph and new binder DIFFER

crates/solidity/testing/snapshots/bindings_output/yul/imported_deconstructed_constants/diff/generated/0.4.11-failure-same.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.
2+
3+
Ref: ["FOO" @ main.sol:6:26] -> #1 resolved uniquely but resolved ambiguously in stack graph output
4+
5+
Definitions and/or references from binding graph and new binder DIFFER

crates/solidity/testing/snapshots/bindings_output/yul/imported_deconstructed_constants/generated/0.4.11-failure.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ References and definitions:
2222
│ │ │
2323
│ ╰─────── ref: built-in
2424
│ │
25-
│ ╰─── unresolved
25+
│ ╰─── ref: 1
2626
───╯
2727
Definiens:
2828
╭─[main.sol:1:1]

crates/solidity/testing/snapshots/bindings_output/yul/imported_deconstructed_constants/generated/0.6.0-failure.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ References and definitions:
2222
│ │ │
2323
│ ╰─────── ref: built-in
2424
│ │
25-
│ ╰─── unresolved
25+
│ ╰─── ref: 1
2626
───╯
2727
Definiens:
2828
╭─[main.sol:1:1]

0 commit comments

Comments
 (0)