argotorg / argotorg/solidity

Self-Defining of State Variables

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

Description

## Description

UPDATE: The issue is not about `Enum` but self defining of state variables:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

contract Test {
address public yolo = yolo;
}
```

The above compiles.

---

[OLD VERSION]

`Enum` values can be implicitly assigned & converted to state variables if named in the same way as the `Enum` entry.

```solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

contract Enum {
enum SomeEnum { yolo }
// Only works if I call the variable the same as the `Enum` value.
address private yolo = yolo;

function enumTest() external view returns (address) {
return yolo;
}
}
```

I don't think this should compile. You can test it with other types, and it will work in the same way.

## Environment

- Compiler version: `0.8.25`
- Target EVM version (as per compiler settings): `shangai`
- Framework/IDE (e.g. Truffle or Remix): `chisel` or `remix`
- EVM execution environment / backend / blockchain client: Foundry
- Operating system: `Linux`

Contributor guide

Open the contributing guide

Research direction

Reproduce the shown self-referential state-variable example with Solidity 0.8.25 in Remix, Chisel, or Foundry, then trace the compiler's name-resolution behavior for the initializer. Done means the intended behavior is specified and covered by a regression test, with compilation producing the expected result.

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
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.