Skip to content

Error parsing v+1 expression (with no spaces around +) #397

@cdevienne

Description

@cdevienne

Given the following enum:

enum Counter {
    Value(Number)
    NoValue
}

I wrote the following code in a component:

  state counter : Counter = Counter::NoValue

  fun inc {
      case (counter) {
        Counter::Value v =>
          next { counter = Counter::Value(v+1) }
        Counter::NoValue =>
          Promise.never()
      }
  }

The message I get from the compiler is:

The body of a record must end with a closing bracket.

I was looking for the bracket } but found ounter::Value(v+1) instead. 

It took me a while to realize that the error came from the absence of whitespaces around the "+" token.

I think the ideal solution would be to accept "v+1" as a valid expression equivalent to "v + 1", but at least we should have a less misleading error message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinglanguageLanguage feature

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions