Skip to content

Arbitrary order of contracts in override specifier is confusing. #8354

Open
@apguerrera

Description

@apguerrera

Version: solidity ^0.6.3
Platform: http://remix.ethereum.org/#optimize=false&evmVersion=null&version=soljson-v0.6.3+commit.8dda9521.js

Issue: override(Two, One) doesn't seam to have the intended behavior. Instead, it retains the contract import inheritance.

Example:

pragma solidity ^0.6.3;

contract One {
    uint256 public a;
    event Hah(string message, uint a, uint b);
    function foo() virtual public {
        a = 1;
        emit Hah("One::foo()", a, 0);
    }
}

contract Two {
    uint256 public b;
    event Hah(string message, uint a, uint b); 
    function foo() virtual public {
        b = 2;
        emit Hah("Two::foo()", 0, b);
    }
}

// Override contract One
contract OneAndTwo is One, Two {
    event Hah(string message, uint a, uint b);
    function foo() public override(One, Two) {
        super.foo();
        emit Hah("OneAndTwo::foo() after super.foo()", a, b);
    }
}
// Calls Two.foo()

// Swap override contracts
contract OneAndTwoReversed is One, Two {
    event Hah(string message, uint a, uint b);
    function foo() public override(Two, One) {        
        super.foo();
        emit Hah("OneAndTwoReversed::foo() after super.foo()", a, b); 
    }
}
// Still calls Two.foo()


// Swap import contracts
contract TwoAndOne is Two, One {
    event Hah(string message, uint a, uint b);
    function foo() public override(Two, One) {
        super.foo();
        emit Hah("TwoAndOne::foo() after super.foo()", a, b);
    }
}
// Now calls One.foo()

Thanks to BokkyPooBah for workshopping this and providing the code examples

Metadata

Metadata

Assignees

No one assigned

    Labels

    annoys users 😢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.must have eventuallySomething we consider essential but not enough to prevent us from releasing Solidity 1.0 without it.needs designThe proposal is too vague to be implemented right away

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions