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:
Bob Nystrom
2013-12-24 18:27:48 +00:00
parent 1a456738f6
commit c58f15fc87
8 changed files with 125 additions and 112 deletions
+3
View File
@@ -0,0 +1,3 @@
IO.write(fn {
if (false) "no" else return "ok"
}.call) // expect: ok
+3
View File
@@ -0,0 +1,3 @@
IO.write(fn {
if (true) return "ok"
}.call) // expect: ok
+3
View File
@@ -0,0 +1,3 @@
IO.write(fn {
while (true) return "ok"
}.call) // expect: ok
+1
View File
@@ -0,0 +1 @@
var a = "ok"; IO.write(a) // expect: ok
+8
View File
@@ -0,0 +1,8 @@
class Foo {
method {
return "ok"
IO.write("bad")
}
}
IO.write((new Foo).method) // expect: ok