-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Public State Variable Overriding #7839
Conversation
{ | ||
FunctionTypePointer functionType = FunctionType(_function).asCallableFunction(false); | ||
string baseTypeName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong title, should be overridingName
Could you add test cases for overriding multiple base functions in multiple inheritance and all the other stuff, even though it won't "work"? It'd still be good to see what happens. |
} | ||
|
||
if constexpr(std::is_same<T, FunctionDefinition>::value) | ||
if (_overriding.stateMutability() != _super.stateMutability()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we should take the feature recently brought to light by @fulldecent still into 0.6.0: Allowing to soften the mutability requirements when overriding. It might get complicated because mutability is not a linear order and also when taking multiple inheritance into account, but maybe not...
That looks really good! |
Even if the check itself seems simple, as @ekpyron we need to check all the cases so that nothing slips under the radar. Things like diamond inheritance where on one branch we have a public state variable and on another we have a function overriding. |
So, this is the output for the diamond test case:
And it's the same for normal multiple inheritance.. |
This currently works, but I would suspect this will no longer work once @christianparpart variable shadow PR is merged |
317a891
to
80cc625
Compare
This is now ready |
80cc625
to
9452104
Compare
9452104
to
44009c3
Compare
docs/contracts/inheritance.rst
Outdated
@@ -244,6 +244,27 @@ overridden when used with multiple inheritance: | |||
|
|||
Functions with the ``private`` visibility cannot be ``virtual``. | |||
|
|||
Public state variables can override external functions with no parameters if the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
interface ERC20 {
function balanceOf(address) external view returns (uint);
}
contract C {
mapping(address => uint) public balanceOf;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That compiles.. should it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I didn't add the is IRC20
part in my test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still works with the fixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then please change the documentation.
test/libsolidity/syntaxTests/inheritance/override/public_vars_multiple.sol
Show resolved
Hide resolved
Apparently I am not checking that the parameters are null.. need to fix that |
Please add a test that shows how this works with overloading, i.e. two functions with the same name in the base contract, once the case where one of the functions matches with regards to parameter types and one case where none of the two match. |
44009c3
to
59acbe5
Compare
Added the cases and extended the logic a bit |
Needs to be rebased. |
it = find_if(++it, funcSet.end(), MatchByName{stateVar->name()}) | ||
) | ||
{ | ||
if ((*it)->visibility() != Declaration::Visibility::External) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it on purpose that this check is not done after the next?
Rebasing this. |
c1bdc65
to
accd83e
Compare
2635e0a
to
ea76d98
Compare
uint public foo; | ||
} | ||
// ---- | ||
// TypeError: (100-115): Base function must be external when overridden by public state variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not too happy with this error message, but it might be fine. At least the error is on the state variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could change it to Public state variable cannot override non-external function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or can only override external function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(functions with external visibility
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy with it because at this point, we do not yet know whether we have the 'override' specifier given or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is specified, then the message is correct.
If it's not, then when they fix the external function, the new message override required here
will appear, so I guess also fine
ea76d98
to
5949ec7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me, can't approve my own PRs though
Rebased and squashed. |
5949ec7
to
45a3681
Compare
45a3681
to
d6cf3a0
Compare
I think some of the test failures are actually correct |
d6cf3a0
to
b7d5de5
Compare
fixed three tests that expected the wrong phrasing |
This is a first draft. Please review the general logic if this is done the way we want.
Details like documentation & changelog will be added ones the basics are approved.
refs #5424
fixes #3514