Solidity: New `constructor` incompatible with fallback function

Created on 17 Apr 2018  路  1Comment  路  Source: ethereum/solidity

With the advent of #3526 in solidity 0.4.22, it would appear that the new constructor keyword stops you having both an empty constructor and a fallback function in the same contract.

Given the following code, contract A will complain that the constructor and fallback have the same name and arguments.

pragma solidity ^0.4.22;

contract A {
    address owner;

    constructor () internal {
        owner = msg.sender;
    }

    function () payable {
        revert();
    }
}

contract B is A {
    uint supply;

    constructor () public {
        supply = 10 ether;
    }
}

This is the error returned:

test.sol:6:5: DeclarationError: Function with same name and arguments defined twice.
    constructor () internal {
    ^ (Relevant source part starts here and spans across multiple lines).
test.sol:10:5: Other declaration is here:
    function () payable {
    ^ (Relevant source part starts here and spans across multiple lines).
bug

Most helpful comment

Argh that's embarassing. I guess we will need a new release soon... Thanks for the report!

>All comments

Argh that's embarassing. I guess we will need a new release soon... Thanks for the report!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chriseth picture chriseth  路  3Comments

ddeclerck picture ddeclerck  路  3Comments

kkagill picture kkagill  路  4Comments

leviadam picture leviadam  路  4Comments

chriseth picture chriseth  路  3Comments