Skip to content

Contract initialization order seems wrong #16205

@d1m0

Description

@d1m0

Page

https://docs.soliditylang.org/en/v0.8.30/ir-breaking-changes.html#semantic-only-changes

Abstract

In the "Semantic only changes" section, the order for initialization of contracts for the old codegen lists "Evaluate base constructor arguments" before "Initialize state variables":

The order used to be:

All state variables are zero-initialized at the beginning.

Evaluate base constructor arguments from most derived to most base contract.

Initialize all state variables in the whole inheritance hierarchy from most base to most derived.

This seems inconsistent with the compiler behavior. The documentation suggests that for the following sample the value of b should be 0, instead its 13:

contract Base {
    uint a = 13;
    uint public b;

    constructor(uint x) public {
        b = x;

    }
}

contract Child is Base {
    constructor() Base(a) public {
    }
}

The documentation seems correct for the IR codegen path.

Pull request

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions