Skip to content

Commit

Permalink
Rules to make user-defined value type resolvable
Browse files Browse the repository at this point in the history
The type's functions `.wrap()` and `.unwrap()` are not yet defined, since they
will be covered when we start support for builtins.
  • Loading branch information
ggiraldez committed Aug 19, 2024
1 parent 249ec48 commit 7bb64cf
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
17 changes: 14 additions & 3 deletions crates/solidity/inputs/language/bindings/rules.msgb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
| [StructDefinition]
| [EventDefinition]
| [ErrorDefinition]
| [UserDefinedValueTypeDefinition]
)]
]] {
edge @member.lexical_scope -> @contract.lexical_scope
Expand Down Expand Up @@ -280,6 +281,7 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
| [StructDefinition]
| [EventDefinition]
| [ErrorDefinition]
| [UserDefinedValueTypeDefinition]
)]
]] {
edge @member.lexical_scope -> @interface.lexical_scope
Expand Down Expand Up @@ -327,6 +329,7 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
| [StructDefinition]
| [EventDefinition]
| [ErrorDefinition]
| [UserDefinedValueTypeDefinition]
)]
]] {
edge @member.lexical_scope -> @library.lexical_scope
Expand Down Expand Up @@ -1066,9 +1069,17 @@ attribute symbol_reference = symbol => type = "push_symbol", symbol = symbol, i
edge @type_name.type_ref -> @constant.lexical_scope
}

@value_type [UserDefinedValueTypeDefinition] {
node @value_type.lexical_scope
node @value_type.def
@user_type [UserDefinedValueTypeDefinition] {
node @user_type.lexical_scope
node @user_type.def
}

@user_type [UserDefinedValueTypeDefinition @name [Identifier]] {
node def
attr (def) node_definition = @name
attr (def) definiens_node = @user_type

edge @user_type.def -> def
}


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,33 @@
contract Test {
// ^def:dummy
type Internal is uint;
// ^def:2 (>= 0.8.8)

function test() public returns (int32) {
Internal inter = Internal.wrap(10);
// ^ref:2 (>= 0.8.8)
//<ref:2 (>= 0.8.8)
TopLevel tl = TopLevel.wrap(20);
// ^ref:1 (>= 0.8.8)
//<ref:1 (>= 0.8.8)
return MyLib.LibType.unwrap(MyLib.create());
// ^ref:3
// ^ref:4 (>= 0.8.8)
// ^ref:3 (>= 0.8.8)
}
}

type TopLevel is uint256;
// ^def:1 (>= 0.8.8)

library MyLib {
// ^def:3
type LibType is int32;
// ^def:4 (>= 0.8.8)

function create() public returns (LibType) {
// ^ref:4 (>= 0.8.8)
return LibType.wrap(30);
// ^ref:4 (>= 0.8.8)
}
}

0 comments on commit 7bb64cf

Please sign in to comment.