New Issue: [design] Should try! apply to an expression without needing braces?

18859, "bmcdonald3", "[design] Should try! apply to an expression without needing braces?", "2021-12-14T19:01:36Z"

Summary

Thinking of the use cases that I have seen for try! (e.g., try! createStringWithNewBuffer(...);), I was under the impression that try! could be applied in the same way as, for example, for i in 0..1 do for j in 2..3 do ..., where you are able to nest the expressions, as long as they are a single line (not sure if this is a hard rule, but it is how I think of it at least. The main idea here is to enable try! to be applied to any expression without braces, similar to for ... do and if .. then.

Problem

try! for i in 0..1 do writeln(i); // gives error

try! { for i in 0..1 do writeln(i); } // no error

for i in 0..1 do for j in 2..3 do writeln(i, j); // seems the same as the first example

if true then for i in 0..1 do writeln(i); // seems the same as the first example

The first line of this snippet does not work, even though it seems to be the same as the brace-less lines 3 and 4.

Additionally, the code on the first line in this snippet will give this error: illegal use of function that does not return a value: 'writeln', which does not seem intuitive/helpful to debug why this does not work.

Proposal

With this in mind, I would like to propose that try! for i in 0..1 do writeln(i); should work in the same way thatfor i in 0..1 do for j in 2..3 do writeln(i, j); works: it is a single expression, so it should not need braces.