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:
@@ -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
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
var f = fn {
|
||||
if (true) { return }
|
||||
IO.print("bad")
|
||||
}
|
||||
|
||||
IO.print(f.call) // expect: null
|
||||
@@ -0,0 +1,6 @@
|
||||
var f = fn {
|
||||
return
|
||||
IO.print("bad")
|
||||
}
|
||||
|
||||
IO.print(f.call) // expect: null
|
||||
Reference in New Issue
Block a user