-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Explicit keyword for abstract contracts #649
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

Comments
If you do not proved base contract constructor arguments, your contract is abstract, as if you did not implement one of the methods. There is nothing wrong with that, so it is not possible to show any error. Having said that, we plan to change the way the compiler is invoked so you can explicitly specify which contract you want to compile (instead of all non-abstract ones). In that case, the compiler can provide an error message and should also tell you the reason why a contract is abstract. |
So maybe a simple keyword 'abstract' could be added like in Java, Scala, C#? This way compiler will have enough information to warn user if his intention was not an abstract contract. Cause I spent some time until I have realized this mistake. In my concrete case I had a big contract which was inheriting from a contract with constructor and I have missed the constructor in derived contract. This resulted in empty bytecode from compiler which seems incorrect. |
So right now the only way to test if it is an abstract contract is by seeing if a bytecode is returned during compilation. For real abstract contracts, that is empty. Fun fact, the below is not abstract:
because it contains only the implicit definition of the fallback function. |
I think having an explicit keyword could aid error reporting. Should it be called |
I think it would be A Very Good Thing to have an explicit @axic I wouldn't use |
@redsquirrel forgot that it can have implemented as well as non-implemented functions. I'm not sure abstract contracts make sense in that case, perhaps marking such functions clearly
I would personally prefer to have a clean
|
As also commented on the "interface" issue: I think having another type of contract is not a good idea and will confuse users. What about: Warn if contract is abstract but not "marked" as abstract. Also having the distinction between explicitly abstract contract and purely abstract (interface) is too fine and confusing. Please let's not go down the path C# went. |
I'd prefer to see it more strictly enforced with an error, but a warning is fine.
I think this is going to confuse people because it looks like inheritance. I'd prefer:
|
Yep, that is how it is done in Typescript, so we could also follow that. |
I think this is a bad idea. It suggests that it is derived from an
Abstract contracts are probably useful to map out source code in a more sensible way. Interfaces on the other hand map the ABI 1-to-1 and have a different use case. It helps to avoid the mistake of using an abstract contract, which has a few extra methods defined, and pointing it to an instance which only has the interface methods available. Take this example:
|
Why would this fail? |
Because the instance of |
Ahhh, I see it now. I thought that |
I like both |
I think we should discuss this again. Currently, there are many situations that lead to a contract being abstract, but you get not notified about that unless you try to instantiate such a contract. If we require a keyword of some sort for such cases, it is much easier to detect. (suggested by @recmo) |
Since we have I would suggest an alternative: I'm still a proponent of making this required. |
As a workaround it'd be good to emit a warning on abstract contracts - this allows for the compiler to give feedback to coders who don't expect the sort of thing I talk about in #4220 Part of the reason this happens is b/c Alternate suggestion: a "strict" pragma (or something) that doesn't allow identically named functions with different arguments. This would allow my case (#4220) to be caught and isn't a breaking change. My feeling is this is a significant issue because it requires the programmer to learn more than should be necessary about the internal functioning of solidity and the compiler, which should not be the default. Good compilers give good feedback (erring on the side of more feedback) and help the programmer as much as possible. My 2 wei. |
I do not think that is a viable approach since we do not have a way to suppress warnings and as a result there would be no way to create abstract contracts without warnings. |
Between the two I would prefer In general I'd prefer a single keyword for abstract contracts, but since |
I think I would prefer |
What about |
I consider Example from https://github.com/0xcert/ethereum-utils/blob/master/contracts/ownership/Ownable.sol
Nobody in their right mind would deploy the In addition to allowing
^^^ Presently this code is legal. I propose that it should be an error "Contracts with unimplemented methods must be explicitly marked as |
Quick decision by show of hands during meeting: In favour for |
To clarify the implementation proposal again:
|
Idea by @axic: An empty contract should be considered not implemented (and thus require |
That can also be achieved by making the constructor internal: contract Ownable {
constructor() internal {
_owner = msg.sender();
}
...
} This is IMO a cleaner approach, since it directly tackles the actual objective: preventing the contract from being deployed. I'd have the |
Implemented in #7358 |
Uh oh!
There was an error while loading. Please reload this page.
Compiler doesn't produce errors, but returns empty bytecode when child contract does not call inherited constructor.
To reproduce:
run
sold child.sol --bin
output:
solc version:
Expected: some error message that child must define constructor
The text was updated successfully, but these errors were encountered: