diff --git a/crates/solidity/inputs/language/bindings/rules.msgb b/crates/solidity/inputs/language/bindings/rules.msgb index eeb5a00bc1..1e794b3a8b 100644 --- a/crates/solidity/inputs/language/bindings/rules.msgb +++ b/crates/solidity/inputs/language/bindings/rules.msgb @@ -2050,6 +2050,36 @@ inherit .star_extension edge @enum.def -> type edge type -> type_enum_type edge type_enum_type -> @enum.lexical_scope + + ; value_ref_typeof allows for an enum value to access the + ; functions associated to this type + node @enum.value_ref_typeof + attr (@enum.value_ref_typeof) push_symbol = "@typeof" + node value_ref_type + attr (value_ref_type) push_symbol = (source-text @name) + edge @enum.value_ref_typeof -> value_ref_type + edge value_ref_type -> @enum.lexical_scope + + ; Path to link min and max to the enum's scope (#1158) + ; It resolves paths of the form `type().min.` + if (version-matches ">= 0.6.8") { + node typeof + attr (typeof) pop_symbol = "@typeof" + + node built_in_member + attr (built_in_member) pop_symbol = "." + node min_built_in + attr (min_built_in) pop_symbol = "min" + node max_built_in + attr (max_built_in) pop_symbol = "max" + + edge type -> typeof + edge typeof -> built_in_member + edge built_in_member -> min_built_in + edge built_in_member -> max_built_in + edge min_built_in -> @enum.value_ref_typeof + edge max_built_in -> @enum.value_ref_typeof + } } @enum [EnumDefinition @@ -2059,6 +2089,7 @@ inherit .star_extension attr (def) node_definition = @item attr (def) definiens_node = @item + edge def -> @enum.value_ref_typeof edge @enum.members -> def } diff --git a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs index af5af31975..a8827dec4c 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/bindings/generated/binding_rules.rs @@ -2055,6 +2055,36 @@ inherit .star_extension edge @enum.def -> type edge type -> type_enum_type edge type_enum_type -> @enum.lexical_scope + + ; value_ref_typeof allows for an enum value to access the + ; functions associated to this type + node @enum.value_ref_typeof + attr (@enum.value_ref_typeof) push_symbol = "@typeof" + node value_ref_type + attr (value_ref_type) push_symbol = (source-text @name) + edge @enum.value_ref_typeof -> value_ref_type + edge value_ref_type -> @enum.lexical_scope + + ; Path to link min and max to the enum's scope (#1158) + ; It resolves paths of the form `type().min.` + if (version-matches ">= 0.6.8") { + node typeof + attr (typeof) pop_symbol = "@typeof" + + node built_in_member + attr (built_in_member) pop_symbol = "." + node min_built_in + attr (min_built_in) pop_symbol = "min" + node max_built_in + attr (max_built_in) pop_symbol = "max" + + edge type -> typeof + edge typeof -> built_in_member + edge built_in_member -> min_built_in + edge built_in_member -> max_built_in + edge min_built_in -> @enum.value_ref_typeof + edge max_built_in -> @enum.value_ref_typeof + } } @enum [EnumDefinition @@ -2064,6 +2094,7 @@ inherit .star_extension attr (def) node_definition = @item attr (def) definiens_node = @item + edge def -> @enum.value_ref_typeof edge @enum.members -> def } diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/expressions.rs b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/expressions.rs index 03d1ff3445..c944702b5a 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/expressions.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/expressions.rs @@ -73,3 +73,8 @@ fn revert_named_args() -> Result<()> { fn type_expr() -> Result<()> { run("expressions", "type_expr") } + +#[test] +fn type_expr_minmax() -> Result<()> { + run("expressions", "type_expr_minmax") +} diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/using.rs b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/using.rs index 7b8a7d7bff..ed4d22c7d4 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/using.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/using.rs @@ -9,6 +9,16 @@ fn address() -> Result<()> { run("using", "address") } +#[test] +fn binding_enum() -> Result<()> { + run("using", "binding_enum") +} + +#[test] +fn binding_enum_member() -> Result<()> { + run("using", "binding_enum_member") +} + #[test] fn casting() -> Result<()> { run("using", "casting") diff --git a/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.4.11-failure.txt b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.4.11-failure.txt new file mode 100644 index 0000000000..a759f22a82 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.4.11-failure.txt @@ -0,0 +1,14 @@ +# 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 │ ╭─▶ enum Answer { + ┆ ┆ + 18 │ ├─▶ } + │ │ + │ ╰─────── Error occurred here. +────╯ +References and definitions: +Definiens: diff --git a/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.6.0-failure.txt b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.6.0-failure.txt new file mode 100644 index 0000000000..ae4ac88a5c --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.6.0-failure.txt @@ -0,0 +1,88 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +References and definitions: + ╭─[input.sol:1:1] + │ + 1 │ enum Answer { + │ ───┬── + │ ╰──── name: 1 + 2 │ Yes + │ ─┬─ + │ ╰─── name: 2 + │ + 5 │ library Id { + │ ─┬ + │ ╰── name: 3 + 6 │ function id(Answer ans) returns (Answer) { + │ ─┬ ───┬── ─┬─ ───┬── + │ ╰────────────────────────────── name: 4 + │ │ │ │ + │ ╰───────────────────────── ref: 1 + │ │ │ + │ ╰──────────────────── name: 5 + │ │ + │ ╰──── ref: 1 + 7 │ return ans; + │ ─┬─ + │ ╰─── ref: 5 + │ + 11 │ contract Test { + │ ──┬─ + │ ╰─── name: 6 + 12 │ using Id for Answer; + │ ─┬ ───┬── + │ ╰───────────── ref: 3 + │ │ + │ ╰──── ref: 1 + │ + 14 │ function testFunc() { + │ ────┬─── + │ ╰───── name: 7 + 15 │ type(Answer).min.id(); + │ ───┬── ─┬─ ─┬ + │ ╰──────────── ref: 1 + │ │ │ + │ ╰────── unresolved + │ │ + │ ╰── unresolved + 16 │ type(Answer).max.id(); + │ ───┬── ─┬─ ─┬ + │ ╰──────────── ref: 1 + │ │ │ + │ ╰────── unresolved + │ │ + │ ╰── unresolved +────╯ +Definiens: + ╭─[input.sol:1:1] + │ + 1 │ ╭─▶ enum Answer { + 2 │ │ Yes + │ │ ─┬─ + │ │ ╰─── definiens: 2 + 3 │ │ ├─▶ } + │ │ │ + │ │ ╰─────── definiens: 1 + 4 │ ╭─────▶ + ┆ ┆ ┆ + 6 │ │ ╭───▶ function id(Answer ans) returns (Answer) { + │ │ │ ─────┬──── + │ │ │ ╰────── definiens: 5 + ┆ ┆ ┆ + 8 │ │ ├───▶ } + │ │ │ + │ │ ╰─────────── definiens: 4 + 9 │ │ ├─────▶ } + │ │ │ + │ │ ╰─────────── definiens: 3 + 10 │ ╭─────────▶ + ┆ ┆ + 13 │ │ ╭───────▶ + ┆ ┆ ┆ + 17 │ │ ├───────▶ } + │ │ │ + │ │ ╰─────────────── definiens: 7 + 18 │ ├─────────▶ } + │ │ + │ ╰─────────────── definiens: 6 +────╯ diff --git a/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.6.8-success.txt b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.6.8-success.txt new file mode 100644 index 0000000000..fa55cac0cf --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/generated/0.6.8-success.txt @@ -0,0 +1,88 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +References and definitions: + ╭─[input.sol:1:1] + │ + 1 │ enum Answer { + │ ───┬── + │ ╰──── name: 1 + 2 │ Yes + │ ─┬─ + │ ╰─── name: 2 + │ + 5 │ library Id { + │ ─┬ + │ ╰── name: 3 + 6 │ function id(Answer ans) returns (Answer) { + │ ─┬ ───┬── ─┬─ ───┬── + │ ╰────────────────────────────── name: 4 + │ │ │ │ + │ ╰───────────────────────── ref: 1 + │ │ │ + │ ╰──────────────────── name: 5 + │ │ + │ ╰──── ref: 1 + 7 │ return ans; + │ ─┬─ + │ ╰─── ref: 5 + │ + 11 │ contract Test { + │ ──┬─ + │ ╰─── name: 6 + 12 │ using Id for Answer; + │ ─┬ ───┬── + │ ╰───────────── ref: 3 + │ │ + │ ╰──── ref: 1 + │ + 14 │ function testFunc() { + │ ────┬─── + │ ╰───── name: 7 + 15 │ type(Answer).min.id(); + │ ───┬── ─┬─ ─┬ + │ ╰──────────── ref: 1 + │ │ │ + │ ╰────── ref: built-in + │ │ + │ ╰── ref: 4 + 16 │ type(Answer).max.id(); + │ ───┬── ─┬─ ─┬ + │ ╰──────────── ref: 1 + │ │ │ + │ ╰────── ref: built-in + │ │ + │ ╰── ref: 4 +────╯ +Definiens: + ╭─[input.sol:1:1] + │ + 1 │ ╭─▶ enum Answer { + 2 │ │ Yes + │ │ ─┬─ + │ │ ╰─── definiens: 2 + 3 │ │ ├─▶ } + │ │ │ + │ │ ╰─────── definiens: 1 + 4 │ ╭─────▶ + ┆ ┆ ┆ + 6 │ │ ╭───▶ function id(Answer ans) returns (Answer) { + │ │ │ ─────┬──── + │ │ │ ╰────── definiens: 5 + ┆ ┆ ┆ + 8 │ │ ├───▶ } + │ │ │ + │ │ ╰─────────── definiens: 4 + 9 │ │ ├─────▶ } + │ │ │ + │ │ ╰─────────── definiens: 3 + 10 │ ╭─────────▶ + ┆ ┆ + 13 │ │ ╭───────▶ + ┆ ┆ ┆ + 17 │ │ ├───────▶ } + │ │ │ + │ │ ╰─────────────── definiens: 7 + 18 │ ├─────────▶ } + │ │ + │ ╰─────────────── definiens: 6 +────╯ diff --git a/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/input.sol b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/input.sol new file mode 100644 index 0000000000..df73d9d15a --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/expressions/type_expr_minmax/input.sol @@ -0,0 +1,18 @@ +enum Answer { + Yes +} + +library Id { + function id(Answer ans) returns (Answer) { + return ans; + } +} + +contract Test { + using Id for Answer; + + function testFunc() { + type(Answer).min.id(); + type(Answer).max.id(); + } +} diff --git a/crates/solidity/testing/snapshots/bindings_output/using/binding_enum/generated/0.4.11-success.txt b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum/generated/0.4.11-success.txt new file mode 100644 index 0000000000..c4e362d464 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum/generated/0.4.11-success.txt @@ -0,0 +1,102 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +References and definitions: + ╭─[input.sol:1:1] + │ + 1 │ library Id { + │ ─┬ + │ ╰── name: 1 + 2 │ enum Answer { + │ ───┬── + │ ╰──── name: 2 + 3 │ Yes + │ ─┬─ + │ ╰─── name: 3 + │ + 6 │ function id(Answer ans) returns (Answer) { + │ ─┬ ───┬── ─┬─ ───┬── + │ ╰────────────────────────────── name: 4 + │ │ │ │ + │ ╰───────────────────────── ref: 2 + │ │ │ + │ ╰──────────────────── name: 5 + │ │ + │ ╰──── ref: 2 + 7 │ return ans; + │ ─┬─ + │ ╰─── ref: 5 + │ + 11 │ contract Test { + │ ──┬─ + │ ╰─── name: 6 + 12 │ using Id for Id.Answer; + │ ─┬ ─┬ ───┬── + │ ╰──────────────── ref: 1 + │ │ │ + │ ╰───────── ref: 1 + │ │ + │ ╰──── ref: 2 + │ + 14 │ function testFunc() returns (Id.Answer) { + │ ────┬─── ─┬ ───┬── + │ ╰────────────────────────── name: 7 + │ │ │ + │ ╰───────── ref: 1 + │ │ + │ ╰──── ref: 2 + 15 │ Id.Answer value = Id.Answer.Yes; + │ ─┬ ───┬── ──┬── ─┬ ───┬── ─┬─ + │ ╰─────────────────────────────── ref: 1 + │ │ │ │ │ │ + │ ╰────────────────────────── ref: 2 + │ │ │ │ │ + │ ╰──────────────────── name: 8 + │ │ │ │ + │ ╰───────────── ref: 1 + │ │ │ + │ ╰──────── ref: 2 + │ │ + │ ╰─── ref: 3 + 16 │ value.id(); + │ ──┬── ─┬ + │ ╰─────── ref: 8 + │ │ + │ ╰── ref: 4 +────╯ +Definiens: + ╭─[input.sol:1:1] + │ + 1 │ ╭─────│ ▶ library Id { + 2 │ │ ╭─▶ enum Answer { + 3 │ │ │ Yes + │ │ │ ─┬─ + │ │ │ ╰─── definiens: 3 + 4 │ │ │ ├─▶ } + │ │ │ │ + │ │ │ ╰───────── definiens: 2 + 5 │ │ ╭───▶ + 6 │ │ │ function id(Answer ans) returns (Answer) { + │ │ │ ─────┬──── + │ │ │ ╰────── definiens: 5 + ┆ ┆ ┆ + 8 │ │ ├───▶ } + │ │ │ + │ │ ╰─────────── definiens: 4 + 9 │ │ ├───────▶ } + │ │ │ + │ │ ╰───────────── definiens: 1 + 10 │ ╭─────────▶ + ┆ ┆ + 13 │ │ ╭─────▶ + ┆ ┆ ┆ + 15 │ │ │ Id.Answer value = Id.Answer.Yes; + │ │ │ ──────────────────┬────────────────── + │ │ │ ╰──────────────────── definiens: 8 + ┆ ┆ ┆ + 17 │ │ ├─────▶ } + │ │ │ + │ │ ╰───────────── definiens: 7 + 18 │ ├─────────▶ } + │ │ + │ ╰─────────────── definiens: 6 +────╯ diff --git a/crates/solidity/testing/snapshots/bindings_output/using/binding_enum/input.sol b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum/input.sol new file mode 100644 index 0000000000..cb062d9843 --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum/input.sol @@ -0,0 +1,18 @@ +library Id { + enum Answer { + Yes + } + + function id(Answer ans) returns (Answer) { + return ans; + } +} + +contract Test { + using Id for Id.Answer; + + function testFunc() returns (Id.Answer) { + Id.Answer value = Id.Answer.Yes; + value.id(); + } +} diff --git a/crates/solidity/testing/snapshots/bindings_output/using/binding_enum_member/generated/0.4.11-success.txt b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum_member/generated/0.4.11-success.txt new file mode 100644 index 0000000000..58399ede7f --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum_member/generated/0.4.11-success.txt @@ -0,0 +1,89 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +References and definitions: + ╭─[input.sol:1:1] + │ + 1 │ library Id { + │ ─┬ + │ ╰── name: 1 + 2 │ enum Answer { + │ ───┬── + │ ╰──── name: 2 + 3 │ Yes + │ ─┬─ + │ ╰─── name: 3 + │ + 6 │ function id(Answer ans) returns (Answer) { + │ ─┬ ───┬── ─┬─ ───┬── + │ ╰────────────────────────────── name: 4 + │ │ │ │ + │ ╰───────────────────────── ref: 2 + │ │ │ + │ ╰──────────────────── name: 5 + │ │ + │ ╰──── ref: 2 + 7 │ return ans; + │ ─┬─ + │ ╰─── ref: 5 + │ + 11 │ contract Test { + │ ──┬─ + │ ╰─── name: 6 + 12 │ using Id for Id.Answer; + │ ─┬ ─┬ ───┬── + │ ╰──────────────── ref: 1 + │ │ │ + │ ╰───────── ref: 1 + │ │ + │ ╰──── ref: 2 + │ + 14 │ function testFunc() returns (Id.Answer) { + │ ────┬─── ─┬ ───┬── + │ ╰────────────────────────── name: 7 + │ │ │ + │ ╰───────── ref: 1 + │ │ + │ ╰──── ref: 2 + 15 │ Id.Answer.Yes.id(); + │ ─┬ ───┬── ─┬─ ─┬ + │ ╰──────────────── ref: 1 + │ │ │ │ + │ ╰─────────── ref: 2 + │ │ │ + │ ╰────── ref: 3 + │ │ + │ ╰── ref: 4 +────╯ +Definiens: + ╭─[input.sol:1:1] + │ + 1 │ ╭─────│ ▶ library Id { + 2 │ │ ╭─▶ enum Answer { + 3 │ │ │ Yes + │ │ │ ─┬─ + │ │ │ ╰─── definiens: 3 + 4 │ │ │ ├─▶ } + │ │ │ │ + │ │ │ ╰───────── definiens: 2 + 5 │ │ ╭───▶ + 6 │ │ │ function id(Answer ans) returns (Answer) { + │ │ │ ─────┬──── + │ │ │ ╰────── definiens: 5 + ┆ ┆ ┆ + 8 │ │ ├───▶ } + │ │ │ + │ │ ╰─────────── definiens: 4 + 9 │ │ ├───────▶ } + │ │ │ + │ │ ╰───────────── definiens: 1 + 10 │ ╭─────────▶ + ┆ ┆ + 13 │ │ ╭─────▶ + ┆ ┆ ┆ + 16 │ │ ├─────▶ } + │ │ │ + │ │ ╰───────────── definiens: 7 + 17 │ ├─────────▶ } + │ │ + │ ╰─────────────── definiens: 6 +────╯ diff --git a/crates/solidity/testing/snapshots/bindings_output/using/binding_enum_member/input.sol b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum_member/input.sol new file mode 100644 index 0000000000..c84c0bf1dd --- /dev/null +++ b/crates/solidity/testing/snapshots/bindings_output/using/binding_enum_member/input.sol @@ -0,0 +1,17 @@ +library Id { + enum Answer { + Yes + } + + function id(Answer ans) returns (Answer) { + return ans; + } +} + +contract Test { + using Id for Id.Answer; + + function testFunc() returns (Id.Answer) { + Id.Answer.Yes.id(); + } +}