feat: allow statement bodies for flow control in compiler and add return tests
Replace the block() function's expression-only body with a call to definition(), enabling flow control statements like `if (foo) return bar` and `if (i > 2) break` without requiring curly braces. Add new test files for return statements after if, else, while, and inside functions/methods, and update existing break tests to use the simplified syntax.
This commit is contained in:
@@ -2,10 +2,7 @@ var i = 0
|
||||
while (true) {
|
||||
i = i + 1
|
||||
IO.write(i)
|
||||
if (i > 2) {
|
||||
// TODO: Should not require block for break.
|
||||
break
|
||||
}
|
||||
if (i > 2) break
|
||||
IO.write(i)
|
||||
}
|
||||
// expect: 1
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
var i = 0
|
||||
while (true) {
|
||||
IO.write("outer " + i.toString)
|
||||
if (i > 1) {
|
||||
// TODO: Should not require block for break.
|
||||
break
|
||||
}
|
||||
if (i > 1) break
|
||||
|
||||
var j = 0
|
||||
while (true) {
|
||||
IO.write("inner " + j.toString)
|
||||
if (j > 1) {
|
||||
// TODO: Should not require block for break.
|
||||
break
|
||||
}
|
||||
if (j > 1) break
|
||||
|
||||
j = j + 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user