Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self-Defining of State Variables #15070

Open
pcaversaccio opened this issue Apr 30, 2024 · 1 comment
Open

Self-Defining of State Variables #15070

pcaversaccio opened this issue Apr 30, 2024 · 1 comment
Labels

Comments

@pcaversaccio
Copy link

pcaversaccio commented Apr 30, 2024

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

  • 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
@pcaversaccio pcaversaccio changed the title Implicit conversion of Enum values to state variables Self-Defining of State Variables Apr 30, 2024
@nishim3
Copy link

nishim3 commented May 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants