-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constructors, interfaces,
this
scope, getters and virtual modifiers (…
…#1102) This PR adds support for several new areas: - Contract constructors are now properly connected to the contract lexical scope - Calling a contract constructor using named parameters - `this` provides a scope with access to the current contracts functions - State variables declared public are exposed as external functions - Improve function modifiers by allowing and correctly resolving inherited and virtual ones - Support interface inheritance
- Loading branch information
Showing
30 changed files
with
1,009 additions
and
172 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
260 changes: 174 additions & 86 deletions
260
...s/solidity/outputs/cargo/slang_solidity/src/generated/bindings/generated/binding_rules.rs
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/contracts.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/interfaces.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
crates/solidity/outputs/cargo/tests/src/bindings_output/generated/modifiers.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...g/snapshots/bindings_output/contracts/constructor_invocation/generated/0.4.11-failure.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
Parse errors: | ||
Error: Expected ConstantKeyword or Identifier or InternalKeyword or PrivateKeyword or PublicKeyword. | ||
╭─[input.sol:2:16] | ||
│ | ||
2 │ constructor(int _x) {} | ||
│ ──────┬───── | ||
│ ╰─────── Error occurred here. | ||
───╯ | ||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract A { | ||
│ ┬ | ||
│ ╰── def: 1 | ||
2 │ constructor(int _x) {} | ||
│ ─────┬───── | ||
│ ╰─────── unresolved | ||
│ | ||
5 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 2 | ||
6 │ function foo() public { | ||
│ ─┬─ | ||
│ ╰─── def: 3 | ||
7 │ new A({_x: 2}); | ||
│ ┬ ─┬ | ||
│ ╰────── ref: 1 | ||
│ │ | ||
│ ╰── unresolved | ||
───╯ |
24 changes: 24 additions & 0 deletions
24
...g/snapshots/bindings_output/contracts/constructor_invocation/generated/0.4.22-success.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract A { | ||
│ ┬ | ||
│ ╰── def: 1 | ||
2 │ constructor(int _x) {} | ||
│ ─┬ | ||
│ ╰── def: 2 | ||
│ | ||
5 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 3 | ||
6 │ function foo() public { | ||
│ ─┬─ | ||
│ ╰─── def: 4 | ||
7 │ new A({_x: 2}); | ||
│ ┬ ─┬ | ||
│ ╰────── ref: 1 | ||
│ │ | ||
│ ╰── ref: 2 | ||
───╯ |
9 changes: 9 additions & 0 deletions
9
crates/solidity/testing/snapshots/bindings_output/contracts/constructor_invocation/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
contract A { | ||
constructor(int _x) {} | ||
} | ||
|
||
contract Test { | ||
function foo() public { | ||
new A({_x: 2}); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ing/snapshots/bindings_output/contracts/constructor_modifier/generated/0.4.11-failure.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
Parse errors: | ||
Error: Expected ConstantKeyword or Identifier or InternalKeyword or PrivateKeyword or PublicKeyword. | ||
╭─[input.sol:7:17] | ||
│ | ||
7 │ constructor (address _addr) validAddress(_addr) {} | ||
│ ───────────────────┬─────────────────── | ||
│ ╰───────────────────── Error occurred here. | ||
───╯ | ||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 1 | ||
2 │ modifier validAddress(address _addr) { | ||
│ ──────┬───── ──┬── | ||
│ ╰───────────────────── def: 2 | ||
│ │ | ||
│ ╰──── def: 3 | ||
3 │ require(_addr != address(0), "Not valid address"); | ||
│ ───┬─── ──┬── | ||
│ ╰─────────── unresolved | ||
│ │ | ||
│ ╰──── ref: 3 | ||
4 │ _; | ||
│ ┬ | ||
│ ╰── unresolved | ||
│ | ||
7 │ constructor (address _addr) validAddress(_addr) {} | ||
│ ─────┬───── | ||
│ ╰─────── unresolved | ||
───╯ |
30 changes: 30 additions & 0 deletions
30
...ing/snapshots/bindings_output/contracts/constructor_modifier/generated/0.4.22-success.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 1 | ||
2 │ modifier validAddress(address _addr) { | ||
│ ──────┬───── ──┬── | ||
│ ╰───────────────────── def: 2 | ||
│ │ | ||
│ ╰──── def: 3 | ||
3 │ require(_addr != address(0), "Not valid address"); | ||
│ ───┬─── ──┬── | ||
│ ╰─────────── unresolved | ||
│ │ | ||
│ ╰──── ref: 3 | ||
4 │ _; | ||
│ ┬ | ||
│ ╰── unresolved | ||
│ | ||
7 │ constructor (address _addr) validAddress(_addr) {} | ||
│ ──┬── ──────┬───── ──┬── | ||
│ ╰──────────────────────── def: 4 | ||
│ │ │ | ||
│ ╰───────────── ref: 2 | ||
│ │ | ||
│ ╰──── ref: 4 | ||
───╯ |
8 changes: 8 additions & 0 deletions
8
crates/solidity/testing/snapshots/bindings_output/contracts/constructor_modifier/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
contract Test { | ||
modifier validAddress(address _addr) { | ||
require(_addr != address(0), "Not valid address"); | ||
_; | ||
} | ||
|
||
constructor (address _addr) validAddress(_addr) {} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ity/testing/snapshots/bindings_output/contracts/constructors/generated/0.4.11-failure.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
Parse errors: | ||
Error: Expected ConstantKeyword or Identifier or InternalKeyword or PrivateKeyword or PublicKeyword. | ||
╭─[input.sol:4:16] | ||
│ | ||
4 │ ╭─▶ constructor(string memory _name) { | ||
┆ ┆ | ||
6 │ ├─▶ } | ||
│ │ | ||
│ ╰─────────── Error occurred here. | ||
───╯ | ||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 1 | ||
2 │ string public name; | ||
│ ──┬─ | ||
│ ╰─── def: 2 | ||
│ | ||
4 │ constructor(string memory _name) { | ||
│ ─────┬───── | ||
│ ╰─────── unresolved | ||
───╯ |
21 changes: 21 additions & 0 deletions
21
...ity/testing/snapshots/bindings_output/contracts/constructors/generated/0.4.22-success.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 1 | ||
2 │ string public name; | ||
│ ──┬─ | ||
│ ╰─── def: 2 | ||
│ | ||
4 │ constructor(string memory _name) { | ||
│ ──┬── | ||
│ ╰──── def: 3 | ||
5 │ name = _name; | ||
│ ──┬─ ──┬── | ||
│ ╰─────────── ref: 2 | ||
│ │ | ||
│ ╰──── ref: 3 | ||
───╯ |
7 changes: 7 additions & 0 deletions
7
crates/solidity/testing/snapshots/bindings_output/contracts/constructors/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract Test { | ||
string public name; | ||
|
||
constructor(string memory _name) { | ||
name = _name; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...y/testing/snapshots/bindings_output/contracts/public_getters/generated/0.4.11-success.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract Foo { | ||
│ ─┬─ | ||
│ ╰─── def: 1 | ||
2 │ int public x; | ||
│ ┬ | ||
│ ╰── def: 2 | ||
│ | ||
5 │ contract Bar { | ||
│ ─┬─ | ||
│ ╰─── def: 3 | ||
6 │ int public y; | ||
│ ┬ | ||
│ ╰── def: 4 | ||
7 │ Foo f; | ||
│ ─┬─ ┬ | ||
│ ╰───── ref: 1 | ||
│ │ | ||
│ ╰── def: 5 | ||
│ | ||
9 │ function test() public returns (int) { | ||
│ ──┬─ | ||
│ ╰─── def: 6 | ||
10 │ return y + this.y() + f.x(); | ||
│ ┬ ──┬─ ┬ ┬ ┬ | ||
│ ╰─────────────────── ref: 4 | ||
│ │ │ │ │ | ||
│ ╰───────────── unresolved | ||
│ │ │ │ | ||
│ ╰────────── ref: 4 | ||
│ │ │ | ||
│ ╰──── ref: 5 | ||
│ │ | ||
│ ╰── ref: 2 | ||
────╯ |
12 changes: 12 additions & 0 deletions
12
crates/solidity/testing/snapshots/bindings_output/contracts/public_getters/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
contract Foo { | ||
int public x; | ||
} | ||
|
||
contract Bar { | ||
int public y; | ||
Foo f; | ||
|
||
function test() public returns (int) { | ||
return y + this.y() + f.x(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...idity/testing/snapshots/bindings_output/contracts/this_scope/generated/0.4.11-success.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This file is generated automatically by infrastructure scripts. Please don't edit by hand. | ||
|
||
References and definitions: | ||
╭─[input.sol:1:1] | ||
│ | ||
1 │ contract Test { | ||
│ ──┬─ | ||
│ ╰─── def: 1 | ||
2 │ function foo() public {} | ||
│ ─┬─ | ||
│ ╰─── def: 2 | ||
│ | ||
4 │ function bar() public returns (int) { | ||
│ ─┬─ | ||
│ ╰─── def: 3 | ||
5 │ this.foo(); | ||
│ ──┬─ ─┬─ | ||
│ ╰─────── unresolved | ||
│ │ | ||
│ ╰─── ref: 2 | ||
───╯ |
7 changes: 7 additions & 0 deletions
7
crates/solidity/testing/snapshots/bindings_output/contracts/this_scope/input.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract Test { | ||
function foo() public {} | ||
|
||
function bar() public returns (int) { | ||
this.foo(); | ||
} | ||
} |
Oops, something went wrong.