Skip to content

Self assignment at declaration (ambiguous construct) #2495

@axic

Description

@axic

The following compiles without issues:

contract C {
  function f() {
    int a = a;
  }
}

Since variables are pre initialised to 0, the above should be effectively a no-op. I do think however it can be confusing. I would suggest throwing an error in this case or at a bare minimum a warning.

Think about:

  int aa = 5;
  int a = 4 * a; // user intended to use aa

The same applies to var, though that is already rejected (for a different reason):

2988.sol:3:13: Error: Declaration referenced before type could be determined.
    var a = a;
            ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions