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

Incorrect constructor inheritance #1428

Open
xermicus opened this issue Jul 6, 2023 · 0 comments
Open

Incorrect constructor inheritance #1428

xermicus opened this issue Jul 6, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@xermicus
Copy link
Contributor

xermicus commented Jul 6, 2023

The code example about linearization of constructors from the Solidity docs produces wrong code:

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Base1 {
        uint public foo;
    constructor() {}
}

abstract contract Base2 {
    constructor() {}
}

// Constructors are executed in the following order:
//  1 - Base1
//  2 - Base2
//  3 - Derived1
contract Derived1 is Base1, Base2 {
    constructor() Base1() Base2() {}
}

// Constructors are executed in the following order:
//  1 - Base2
//  2 - Base1
//  3 - Derived2
contract Derived2 is Base2, Base1 {
    constructor() Base2() Base1() {}
}

// Constructors are still executed in the following order:
//  1 - Base2
//  2 - Base1
//  3 - Derived3
contract Derived3 is Base2, Base1 {
    constructor() Base1() Base2() {}
}

Instead of what is explained in the comment of the example contracts, the constructors look like this:

# constructor Derived1::Derived1::constructor::872ccdc6190148bc public:true selector:872ccdc6190148bc nonpayable:true
# params: 
# returns: 
block0: # entry
         = call Derived1::Base2::constructor::872ccdc6190148bc 
         = call Derived1::Base1::constructor::872ccdc6190148bc 
        return 
# constructor Derived2::Derived2::constructor::872ccdc6190148bc public:true selector:872ccdc6190148bc nonpayable:true
# params: 
# returns: 
block0: # entry
         = call Derived2::Base1::constructor::872ccdc6190148bc 
         = call Derived2::Base2::constructor::872ccdc6190148bc 
        return 
# constructor Derived3::Derived3::constructor::872ccdc6190148bc public:true selector:872ccdc6190148bc nonpayable:true
# params: 
# returns: 
block0: # entry
         = call Derived3::Base1::constructor::872ccdc6190148bc 
         = call Derived3::Base2::constructor::872ccdc6190148bc 
        return

The same is the case when compiling for the polkadot target.

@xermicus xermicus added the bug Something isn't working label Jul 6, 2023
@xermicus xermicus added this to the Openzepplin on Substrate milestone Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
@xermicus and others