mint icon indicating copy to clipboard operation
mint copied to clipboard

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

Open cdevienne opened this issue 4 years ago • 0 comments

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.

cdevienne avatar Apr 15 '21 16:04 cdevienne