ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
22.64k stars 5.61k forks source link

Self-Defining of State Variables #15070

Open pcaversaccio opened 1 month ago

pcaversaccio commented 1 month ago

Description

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

// 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.

// 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

nishim3 commented 1 month ago

Turns out the part tot he right of the = sign is ignored, and the variable gets initialised with the default value.