Skip to content
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

Constructor ignores visibility modifier #979

Closed
axic opened this issue Aug 31, 2016 · 3 comments
Closed

Constructor ignores visibility modifier #979

axic opened this issue Aug 31, 2016 · 3 comments
Assignees
Milestone

Comments

@axic
Copy link
Member

axic commented Aug 31, 2016

For any of the visibilities (internal, external, private, public):

contract Test {
    function Test() internal {
    }
}

the following ABI is generated: [{"inputs":[],"type":"constructor"}], and contract deployment works without hiccups.

I think it would make sense rejecting any visibility modifier on the constructor. Are there any cases currently where a non-public constructor is useful? We do not have static methods, so I don't see a way a non-public constructor could be executed.

@axic
Copy link
Member Author

axic commented Aug 31, 2016

Fixing this will also "fix" #422.

@chriseth
Copy link
Contributor

A non-public constructor is useful for base classes. We should enforce visibility and make contracts with non-public constructors abstract.

@chriseth chriseth added this to the 3-easy-bugs milestone Aug 31, 2016
@chriseth chriseth added the soon label Aug 31, 2016
@chriseth
Copy link
Contributor

chriseth commented Sep 1, 2016

An external constructor does not make much sense. The external keyword more or less forces all parameters to be in calldata, although constructor arguments are either in code or in memory. Furthermore, the other purpose of external is that such a function cannot be called internally. As constructors cannot really be "called" anyway, I would say it is fine to disallow external for constructors.

Therefore, I would say we should only allow internal and public for constructors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants