Reason: Put parens back to switch (foo) in the printer

Created on 23 Dec 2017  路  7Comments  路  Source: reasonml/reason

Apparently folks find it confusing that it sometimes need parens and sometimes doesn't.

We can keep the non-parenthesized version in the parser to be lenient, but print the parens.

Same for try catch

Most helpful comment

Yeah, either way, the example is just to show how an innocuous progression of code modifications can lead to a difficult to understand parse error.

All 7 comments

An example of when this is confusing. If I start with this:

let fn = (v1, v2) => switch v1 {
| true => "ok"
| _ => "other"
}

and then modify by adding && v2, like this:

let fn = (v1, v2) => switch v1 && v2 {
| true => "ok"
| _ => "other"
}

I get "UNKNOWN SYNTAX ERROR".

btw for this case, you should use a tuple: https://reasonml.github.io/guide/language/tuple#tips--tricks

Yeah, either way, the example is just to show how an innocuous progression of code modifications can lead to a difficult to understand parse error.

I'd argue for less parentheses in general - it should be possible to not require parentheses in nearly any case, like Rust.

@ubsan that would be my preference as well... I recall some discussion about it earlier but can't find why this was harder to do

This can be closed thanks to #1720 / #1733, correct?

Yep, thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jberdine picture jberdine  路  3Comments

chenglou picture chenglou  路  3Comments

TheSpyder picture TheSpyder  路  3Comments

cristianoc picture cristianoc  路  4Comments

ondrejsevcik picture ondrejsevcik  路  3Comments