feat: allow implicit null return when return statement has no value

In the compiler, when a `return` token is followed by a newline or right brace, emit CODE_NULL instead of parsing an expression. This enables bare `return` statements to implicitly return null. Also removes a stale TODO comment about setter parameters and fixes a typo in a comment in wren_core.c. Adds three test cases: one for explicit return in a function, one for bare return before a brace, and one for bare return before a newline.
This commit is contained in:
Bob Nystrom
2014-01-13 03:37:11 +00:00
parent 2e34a5c42b
commit 08c38f92cb
5 changed files with 28 additions and 6 deletions
+6 -1
View File
@@ -1 +1,6 @@
var a = "ok"; IO.print(a) // expect: ok
var f = fn {
return "ok"
IO.print("bad")
}
IO.print(f.call) // expect: ok
+6
View File
@@ -0,0 +1,6 @@
var f = fn {
if (true) { return }
IO.print("bad")
}
IO.print(f.call) // expect: null
+6
View File
@@ -0,0 +1,6 @@
var f = fn {
return
IO.print("bad")
}
IO.print(f.call) // expect: null