Skip to content

Disallow visibility modifiers on constructors #16167

@cameel

Description

@cameel

Abstract

Constructors can currently have a visibility modifier (internal if abstract, public otherwise), which has no real effect. This is redundant and should be disallowed.

Motivation

In Solidity 0.6.x specifying visibility of a constructor was mandatory. It could be either internal or public. An internal constructor could not be "invoked" from the outside, making the contract undeployable on its own. Such constructor could only be invoked internally, from within a derived contract.

However, the concept did not map 1:1 to the way visibility works for ordinary functions and there were various opinions on how to adjust it (#4392). On the other hand, it lined up exactly with the notion of an abstract contract and was therefore redundant (#8162). In 0.7.0 (#8992) we decided to allow omitting the visibility and disallow abstract contracts with a public constructor as well as non-abstract ones with an internal constructor.

We left the possibility of using the abstract/internal and non-abstract/public combinations open (with a warning). It was argued that this is important for libraries to keep portability across different compiler versions (#9399). Still, the intention was to disallow those eventually as well and now enough time has passed that this should no longer be controversial.

Specification

Report an error when any visibility specifier is used on a contract constructor.

Backwards Compatibility

This is a breaking syntax change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking change ⚠️low effortThere is not much implementation work to be done. The task is very easy or tiny.low impactChanges are not very noticeable or potential benefits are limited.should haveWe like the idea but it’s not important enough to be a part of the roadmap.

    Type

    No type

    Projects

    Status

    Optional

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions