quint icon indicating copy to clipboard operation
quint copied to clipboard

Bad error message for missing parenthesis in the `if` condition

Open bugarela opened this issue 10 months ago • 2 comments

If the if statement is inside an operator call (or probably anything), the parser loses track of the missing parenthesis error, and the reported error is almost meaningless:

module test {
  val foo = Set(1, 2).map(x => if x > 0 { 1 } else { 2 })
}
test.qnt:2:26 - error: [QNT000] extraneous input '(' expecting {'}', 'const', 'var', 'assume', 'type', 'val', 'def', 'pure', 'action', 'run', 'temporal', 'import', 'export', DOCCOMMENT}
2:   val foo = Set(1, 2).map(x => if x > 0 { 1 } else { 2 })
                            ^

test.qnt:2:47 - error: [QNT000] extraneous input 'else' expecting {<EOF>, 'module', DOCCOMMENT}
2:   val foo = Set(1, 2).map(x => if x > 0 { 1 } else { 2 })
                                                 ^^^^

error: parsing failed

bugarela avatar Apr 10 '24 15:04 bugarela

I realize this is only tangentially related, but might it be possible to get rid of the paren requirement altogether?

Rust and OCaml do it :), though OCaml has the benefit of using the then keyword. Rust doesn't need one, though.

eras avatar Apr 17 '24 14:04 eras

One thing to consider is that rust requires the curly braces for the blocks, while we currently don't (which I like). I think my personal preference is to use then, rather than mandating either parenthesis or curly braces.

bugarela avatar Apr 23 '24 11:04 bugarela