Skip to content

Commit

Permalink
Set edge precedences to resolve to nearest method implementations
Browse files Browse the repository at this point in the history
And derived bases in order from right to left.
  • Loading branch information
ggiraldez committed Aug 23, 2024
1 parent 456570b commit 9a41ee9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
11 changes: 10 additions & 1 deletion crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
}

@contract [ContractDefinition [InheritanceSpecifier [InheritanceTypes
[InheritanceType @type_name [IdentifierPath]]
@type [InheritanceType @type_name [IdentifierPath]]
]]] {
;; Resolve contract bases names through the parent scope of the contract (aka
;; the source unit)
Expand All @@ -248,6 +248,7 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
attr (typeof) push_symbol = "@typeof"

edge @contract.members -> member
attr (@contract.members -> member) precedence = 0
edge member -> typeof
edge typeof -> @type_name.right

Expand All @@ -260,6 +261,10 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i

;; The base contract defs are directly accesible through our special super scope
edge @contract.super_scope -> @type_name.right

;; Precedence order for bases defined from right to left (ie. rightmost base has higher precedence)
let p = (plus 1 (named-child-index @type))
attr (@contract.super_scope -> @type_name.right) precedence = p
}

@contract [ContractDefinition [ContractMembers
Expand Down Expand Up @@ -290,6 +295,10 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
]] {
;; Contract functions are also accessible for an instance of the contract
edge @contract.members -> @function.def
;; Contract's own members should have higher precedence than base clases
;; See connection from @contract.members into base type's member in contract
;; bases rules, where the precedence is set to 0
attr (@contract.members -> @function.def) precedence = 1
}

@contract [ContractDefinition [ContractMembers [ContractMember
Expand Down

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 @@ -23,13 +23,13 @@ contract C is A {
contract D is B, C {
function foo() public pure override(B, C) returns (string memory) {
return super.foo();
// ^ref:3 (=0.0.0) -- TODO should resolve for (>=0.6.0)
// ^ref:3
}
}

contract E is C, B {
function foo() public pure override(C, B) returns (string memory) {
return super.foo();
// ^ref:2 (=0.0.0) -- TODO should resolve for (>=0.6.0)
// ^ref:2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ References and definitions:
│ ──┬── ─┬─
│ ╰──────── unresolved
│ │
│ ╰─── ref: 2
│ ╰─── ref: 6
────╯
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ References and definitions:
│ ──┬── ─┬─
│ ╰──────── unresolved
│ │
│ ╰─── ref: 2
│ ╰─── ref: 6
────╯

0 comments on commit 9a41ee9

Please sign in to comment.