-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Make super skip unimplemented functions
#11472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| contract A { | ||
| function f() public virtual returns (uint) { | ||
| return 42; | ||
| } | ||
| } | ||
|
|
||
| abstract contract I { | ||
| function f() external virtual returns (uint); | ||
| } | ||
|
|
||
| contract B is A, I { | ||
| function f() override(A, I) public returns (uint) { | ||
| // I.f() is before A.f() in the C3 linearized order | ||
| // but it has no implementation. | ||
| return super.f(); | ||
| } | ||
| } | ||
| // ==== | ||
| // compileToEwasm: also | ||
| // compileViaYul: also | ||
| // ---- | ||
| // f() -> 42 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| contract A { | ||
| function f() public virtual returns (uint) { | ||
| return 42; | ||
| } | ||
| } | ||
|
|
||
| interface I { | ||
| function f() external returns (uint); | ||
| } | ||
|
|
||
| contract B is A, I { | ||
| function f() override(A, I) public returns (uint) { | ||
| // I.f() is before A.f() in the C3 linearized order | ||
| // but it has no implementation. | ||
| return super.f(); | ||
| } | ||
| } | ||
| // ==== | ||
| // compileToEwasm: also | ||
| // compileViaYul: also | ||
| // ---- | ||
| // f() -> 42 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| abstract contract I { | ||
| function a() internal view virtual returns(uint256); | ||
| } | ||
|
|
||
| abstract contract C is I { | ||
| function f() public view returns(uint256) { | ||
| return I.a(); | ||
| } | ||
| } | ||
|
|
||
| abstract contract D is I { | ||
| function f() public view returns(uint256) { | ||
| return super.a(); | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 7501: (172-177): Cannot call unimplemented base function. | ||
| // TypeError 9582: (278-285): Member "a" not found or not visible after argument-dependent lookup in type(contract super D). | ||
|
Comment on lines
+1
to
+18
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test ensures that we'll not hit the final assert in |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| contract A { | ||
| function f() public virtual {} | ||
| } | ||
| abstract contract B { | ||
| function f() public virtual; | ||
| } | ||
| contract C is A, B { | ||
| function f() public virtual override(A, B) { | ||
| B.f(); // Should not skip over to A.f() just because B.f() has no implementation. | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 7501: (185-190): Cannot call unimplemented base function. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| contract A { | ||
| function f() public virtual {} | ||
| } | ||
| abstract contract B { | ||
| function f() public virtual; | ||
| } | ||
| contract C is A, B { | ||
| function f() public override(A, B) { | ||
| super.f(); // super should skip the unimplemented B.f() and call A.f() instead. | ||
| } | ||
| } | ||
| // ---- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| contract A { | ||
| function f() public virtual {} | ||
| } | ||
| abstract contract B { | ||
| function f() public virtual; | ||
| } | ||
| contract C is A, B { | ||
| function f() public override(A, B) { | ||
| // This is fine. The unimplemented B.f() is not used. | ||
| } | ||
| } | ||
| // ---- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| contract A { | ||
| function f() public virtual {} | ||
| } | ||
| abstract contract B { | ||
| function f() public virtual; | ||
| } | ||
| abstract contract C is A, B { | ||
| function g() public { | ||
| f(); // Would call B.f() if we did not require an override in C. | ||
| } | ||
| } | ||
| // ---- | ||
| // TypeError 6480: (107-243): Derived contract must override function "f". Two or more base classes define function with same name and parameter types. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| contract A { | ||
| function f() public virtual {} | ||
| } | ||
| abstract contract B is A { | ||
| function f() public virtual override; | ||
| } | ||
| contract C is B { | ||
| function f() public virtual override {} | ||
| } | ||
| // ---- | ||
| // TypeError 4593: (81-118): Overriding an implemented function with an unimplemented function is not allowed. | ||
|
Comment on lines
+1
to
+11
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shows that the same problem does not exist without multiple inheritance because we just do not allow unimplemented functions between implemented ones in the resolution chain. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| contract C { | ||
| modifier m() { _; } | ||
| } | ||
| contract D is C { | ||
| function f() super.m public { | ||
| } | ||
| } | ||
| // ---- | ||
| // DeclarationError 7920: (74-81): Identifier not found or not unique. | ||
|
Comment on lines
+1
to
+9
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's also not possible with modifiers because they do not have |
||
Uh oh!
There was an error while loading. Please reload this page.