Skip to content

New constructor incompatible with fallback function #3904

@norganna

Description

@norganna

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).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions