Skip to content

Commit

Permalink
Make using directives inherited in Solidity < 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Oct 25, 2024
1 parent e03fc09 commit 4f858d7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
10 changes: 9 additions & 1 deletion crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,15 @@ inherit .lexical_scope
@contract [ContractDefinition [ContractMembers
[ContractMember @using [UsingDirective]]
]] {
edge @contract.lexical_scope -> @using.def
if (version-matches "< 0.7.0") {
; In Solidity < 0.7.0 using directives are inherited to derived contracts
; Hence we make @using.def accessible through members, which is accessible
; from derived contract's lexical scopes.
edge @contract.members -> @using.def
} else {
; For Solidity >= 0.7.0, using directives are restricted to this contract only.
edge @contract.lexical_scope -> @using.def
}
}

@contract [ContractDefinition [ContractMembers
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.

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
@@ -0,0 +1,16 @@
library Lib {
function squared(int x) public returns (int) { return x * x; }
// ^def:1
}

contract Base {
using Lib for int;
}

contract Test is Base {
function test(int x) public returns (int) {
return x.squared();
// ^ref:1 (< 0.7.0)
// ^ref:! (>= 0.7.0)
}
}

0 comments on commit 4f858d7

Please sign in to comment.