Skip to content

Commit

Permalink
Constructors, interfaces, this scope, getters and virtual modifiers (
Browse files Browse the repository at this point in the history
…NomicFoundation#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
ggiraldez authored Oct 3, 2024
1 parent 21e0082 commit 9126cda
Show file tree
Hide file tree
Showing 30 changed files with 1,009 additions and 172 deletions.
260 changes: 174 additions & 86 deletions crates/solidity/inputs/language/bindings/rules.msgb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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,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
───╯
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
───╯
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});
}
}
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
───╯
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
───╯
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) {}
}
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
───╯
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
───╯
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;
}
}
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
────╯
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();
}
}
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
───╯
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();
}
}
Loading

0 comments on commit 9126cda

Please sign in to comment.