[solc] Unassigned immutables cryptic error
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
```
contract C1 {
bool immutable s1 = false;
constructor() { (int8(127) * 3); }
function f() external returns (bool) {
if (s1)
return true;
else
return false;
}
}
```
```
$ solc --experimental-via-ir --optimize test.sol
...
Warning: Source file does not specify required compiler version!
--> test/libsolidity/semanticTests/testYulCompilerOptimisation.sol
Warning: Statement has no effect.
--> test/libsolidity/semanticTests/testYulCompilerOptimisation.sol:3:19:
|
3 | constructor() { (int8(127) * 3); }
| ^^^^^^^^^^^^^^^
Warning: Function state mutability can be restricted to view
--> test/libsolidity/semanticTests/testYulCompilerOptimisation.sol:4:3:
|
4 | function f() external returns (bool) {
| ^ (Relevant source part starts here and spans across multiple lines).
Error: Some immutables were read from but never assigned, possibly because of optimization.
```
Legacy optimizer does not report and error. Legacy and Sol->Yul without optimization don't report either. Both legacy (with and without opt) and Sol->Yul (without opt) result in a runtime failure due to `int8` overflow inside the constructor.
Contributor guide
Research direction
Reproduce the contract with solc --experimental-via-ir --optimize and compare legacy, Sol-to-Yul, and optimization modes. Start with the immutable-read handling and the semantic test path mentioned in test/libsolidity/semanticTests/testYulCompilerOptimisation.sol; clarify the expected diagnostic and cover the agreed behavior with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100