-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Clean up inheritance and overriding specification #3698
Comments
I think we should have the following minimum requirements: Functions being present in super contracts cannot somehow disappear through adding a sub contract. This means, the visibility can for example change from external to public, but not from public to external or from external to internal. I would say that any other such change is allowed. It is also allowed to restrict the state mutability, but not to relax it. If a function overrides a function from a super contract, it needs the An external function (but not a function of any other visibility) can be overridden by a public state variable. This means that the public state variable also needs the 'override' keyword. It is an error for two contracts in an inheritance hierarchy to have a member of the same name, unless one member (f_B) is defined in a class (B) that derives (directly or indirectly) from the class (A) the other member (f_A) is defined in; and: f_B uses the This in particular means that Furthermore, it is disallowed to inherit members of the same name that come from different base contracts unless they share a common base contract that defines the function to be overridden. The above does not yet capture modifiers. TODO:
|
Interfaces should be allowed to inherit from interfaces. |
My understanding is that
logically follows from
and does on not provide any further prescription. Just to clarify, currently all functions are called with dynamic dispatch. Regarding private functions, I am not sure what the best solution is. Currently we have overrideable with dynamic dispatch. pragma solidity ^0.4.16;
interface HasAName {
function name() external pure returns (string);
}
contract Animal {
function toString() private pure returns (string) {
return "animal";
}
function name() external pure returns (string) {
return toString();
}
function favoriteCrackers() external pure returns (string) {
return /*concat(*/ toString() /*," crackers")*/;
}
}
contract Dog is Animal {
function toString() private pure returns (string) {
return "dog";
}
function name() external pure returns (string) {
return toString();
}
} Another option is no overrides and no dynamic dispatch. As in local declaration. So then the dog's favorite crackers would be animal crackers. The animal crackers solution makes a lot of sense too. This would solve the problem of private name clashes (they are allowed). If you can override modifiers, then virtual modifiers should be allowed. Can you please link to the overloading proposal? Yes, overloading is orthogonal to overriding. Because the fully qualified name for functions is the function selector. A function that returns a different value cannot implement a parent function, this is an error. Exception (actually a note): if animal crackers then private functions don't count as overriding and therefore different returns are allowed. |
We should specify that natspec is inherited.
Here, the |
Interfaces should allow enum definitions.
|
Ok, I already see that this is not the right way to discuss :) |
@OTTTO that idea is for a separate GitHub issue. |
Ok, I created a pull request #3729 - let's continue discussing there. @OTTTO I included your suggestion in the PR. @fulldecent I think I addressed all your comments except for the one about private functions. Are private functions actually used that much? If we allow |
Closing this, please continue the discussion on #3729 |
I have reviewed all my notes here and they are handled or reiterated in the new PR. |
@fulldecent if you want, you can draft a specification here.
The text was updated successfully, but these errors were encountered: