28168, "jabraham17", "What is the expected syntax for 'try'/'try!' expressions", "2025-12-09T23:42:16Z"
I found an oddity with try expressions
// syntax error
if try! foo() || x { }
// syntax error
if x || try! foo() || x { }
// this is fine
if (try! foo()) || x { }
// this is fine
if (try! foo() || x) { }
// this is fine
if x || (try! foo()) { }
// this is NOT fine, syntax error
if (x || try! foo()) { }
It seems weird that if (try! foo() || x) would work but if (x || try! foo()) does not. Its also not clear to me why the parenthesis are required, why can't if try! foo() work (it doesn't today)?
There are similar issues in a variable context
// valid syntax
var x = try foo() || b;
// syntax error
var x = b || try foo();
Its not clear to me if the issue is with precedence/associativity, or if this was an intentional choice. Note the spec on expressions has no mention of try/try! expressions, so at a minimum we need to fix that. Expressions — Chapel Documentation 2.7
If I had to guess, the above cases should all work, and its just a parser implementation issue. But I don't know the full history