feat: allow empty blocks in parser and fix native call slot assertion

Add support for empty block bodies in the Wren compiler by early-returning
from `finishBlock` when a right brace is immediately matched. This permits
syntactically valid constructs like `{}`, `if (true) {}`, and empty function
or method bodies.

Fix a copy-paste error in `wrenGetArgumentDouble` where the assertion
checked `nativeCallSlot` and `nativeCallNumArgs` instead of the correct
`foreignCallSlot` and `foreignCallNumArgs` fields.

Add test cases covering standalone empty blocks, empty blocks in if/else
statements, and empty function and method bodies returning null.
This commit is contained in:
Bob Nystrom
2013-12-29 18:46:21 +00:00
parent 5570f7f46c
commit 4f215f6531
5 changed files with 19 additions and 2 deletions
+2
View File
@@ -0,0 +1,2 @@
var f = fn {}
IO.write(f.call) // expect: null