Skip to content

Commit

Permalink
Add precedence to contract members and top-level definitions
Browse files Browse the repository at this point in the history
This fixes some ambiguities especially with built-ins.
  • Loading branch information
ggiraldez committed Dec 23, 2024
1 parent cb802ad commit afed0c9
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 12 deletions.
3 changes: 3 additions & 0 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ inherit .star_extension
)]
]] {
edge @source_unit.lexical_scope -> @unit_member.def
attr (@source_unit.lexical_scope -> @unit_member.def) precedence = 1

edge @source_unit.defs -> @unit_member.def

; In the general case, the lexical scope of the definition connects directly
Expand Down Expand Up @@ -342,6 +344,7 @@ inherit .star_extension
attr (@contract.def) extension_scope = @contract.extensions

edge @contract.lexical_scope -> @contract.instance
attr (@contract.lexical_scope -> @contract.instance) precedence = 1

; Instance scope can also see members and our namespace definitions
edge @contract.instance -> @contract.members
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Parse errors:
Error: Expected ContractKeyword or ImportKeyword or InterfaceKeyword or LibraryKeyword or PragmaKeyword.
╭─[input.sol:14:1]
14 │ function sha256() {}
│ ──────────┬──────────
│ ╰──────────── Error occurred here.
14 │ ╭─▶ function sha256() {}
┆ ┆
18 │ ├─▶ }
│ │
│ ╰─────── Error occurred here.
────╯
References and definitions:
╭─[input.sol:1:1]
Expand All @@ -29,10 +31,10 @@ References and definitions:
│ ╰──── ref: 4
7 │ tx;
│ ─┬
│ ╰── refs: 2, built-in
│ ╰── ref: 2
8 │ sha256();
│ ───┬──
│ ╰──── refs: 5, built-in
│ ╰──── ref: 5
11 │ function sha256() public {}
│ ───┬──
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Parse errors:
Error: Expected ContractKeyword or EnumKeyword or ImportKeyword or InterfaceKeyword or LibraryKeyword or PragmaKeyword or StructKeyword.
╭─[input.sol:14:1]
14 │ function sha256() {}
│ ──────────┬──────────
│ ╰──────────── Error occurred here.
14 │ ╭─▶ function sha256() {}
┆ ┆
18 │ ├─▶ }
│ │
│ ╰─────── Error occurred here.
────╯
References and definitions:
╭─[input.sol:1:1]
Expand All @@ -29,10 +31,10 @@ References and definitions:
│ ╰──── ref: 4
7 │ tx;
│ ─┬
│ ╰── refs: 2, built-in
│ ╰── ref: 2
8 │ sha256();
│ ───┬──
│ ╰──── refs: 5, built-in
│ ╰──── ref: 5
11 │ function sha256() public {}
│ ───┬──
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ References and definitions:
│ ╰──── ref: 4
7 │ tx;
│ ─┬
│ ╰── refs: 2, built-in
│ ╰── ref: 2
8 │ sha256();
│ ───┬──
│ ╰──── refs: 6, 5, built-in
│ ╰──── ref: 5
11 │ function sha256() public {}
│ ───┬──
Expand All @@ -33,4 +33,11 @@ References and definitions:
14 │ function sha256() {}
│ ───┬──
│ ╰──── def: 6
16 │ function top_level() {
│ ────┬────
│ ╰────── def: 7
17 │ sha256();
│ ───┬──
│ ╰──── ref: 6
────╯
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ contract Test {
}

function sha256() {}

function top_level() {
sha256();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected ContractKeyword or ImportKeyword or InterfaceKeyword or LibraryKeyword or PragmaKeyword.
╭─[input.sol:1:1]
1 │ ╭─▶ function foo() {}
┆ ┆
18 │ ├─▶ }
│ │
│ ╰─────── Error occurred here.
────╯
References and definitions:
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Parse errors:
Error: Expected ContractKeyword or EnumKeyword or ImportKeyword or InterfaceKeyword or LibraryKeyword or PragmaKeyword or StructKeyword.
╭─[input.sol:1:1]
1 │ ╭─▶ function foo() {}
┆ ┆
18 │ ├─▶ }
│ │
│ ╰─────── Error occurred here.
────╯
References and definitions:
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

References and definitions:
╭─[input.sol:1:1]
1 │ function foo() {}
│ ─┬─
│ ╰─── def: 1
2 │ function bar() {}
│ ─┬─
│ ╰─── def: 2
4 │ contract Base {
│ ──┬─
│ ╰─── def: 3
5 │ function bar() public {}
│ ─┬─
│ ╰─── def: 4
8 │ contract Test is Base {
│ ──┬─ ──┬─
│ ╰─────────── def: 5
│ │
│ ╰─── ref: 3
9 │ int x;
│ ┬
│ ╰── def: 6
11 │ function test(int x) public {
│ ──┬─ ┬
│ ╰───────── def: 7
│ │
│ ╰── def: 8
12 │ foo();
│ ─┬─
│ ╰─── ref: 9
13 │ bar();
│ ─┬─
│ ╰─── ref: 4
14 │ x;
│ ┬
│ ╰── ref: 8
17 │ function foo() internal {}
│ ─┬─
│ ╰─── def: 9
────╯
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function foo() {}
function bar() {}

contract Base {
function bar() public {}
}

contract Test is Base {
int x;

function test(int x) public {
foo();
bar();
x;
}

function foo() internal {}
}

0 comments on commit afed0c9

Please sign in to comment.