argotorg / argotorg/solidity

Contract initialization order seems wrong

Open
#16,205 1 comment 0 reactions 0 assignees View on GitHub
documentation :book:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## 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:

```solidity
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

Contributor guide

Open the contributing guide

Research direction

Start with the “Semantic only changes” section at the linked ir-breaking-changes.html page and compare its documented old-codegen initialization order with the supplied Base and Child example. Verify the observed value of b and keep the description distinct from the IR codegen path. Done means the documentation accurately describes both initialization orders.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
compilers, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.