Skip to content

IntLiteral always has negative == false #560

@onbjerg

Description

@onbjerg

Expressions such as -1 are parsed as a UnaryOp and a positive IntLiteral.

Two directions we can go in:

  • When parsing -, we could peek and see if the next peeled literal is an integer literal, which we then construct as negative (preferred)
  • We remove negative from IntegerLiteral and resolve this later

Test cases:

contract C {
    function f() public {
        int8 a = -1;  // negative int literal
        int8 b = -(1); // should be peeled and turned into a negative int literal
        int8 c = -(-1); // unary op negate, negative int literal
        int8 d = -(1 + 2); // unary op negate, binop of two positive int literals
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-semaArea: semantic analysisC-bugCategory: this is a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions