Skip to content

[BUG] incorrect parse of negative number in for-range #1434

@ishani

Description

@ishani

Providing a negative number as the start of a for-range produces broken cpp1 code: the - negative is parsed to apply to the resulting range object rather than the number itself. To make it work one must surround the value with parentheses to clarify possession.

To Reproduce
https://godbolt.org/z/bMafrYvEM

main: () -> int = {
    
    // BROKEN - will not compile
    // produces   -cpp2::range(2,2)   rather than   cpp2::range(-2,2) 
    for -2 ..< 2 do (y) {
        ...
    }

    // WORKAROUND - produces cpp2::range((-2),2) 
    for (-2) ..< 2 do (z) {
        ...
    }

    // NB end value is parsed correctly
    for (-5) ..< -2 do (x) {
        ...
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions