1
0
forked from Mirror/wren

Allow empty blocks.

This commit is contained in:
Bob Nystrom
2013-12-29 10:46:21 -08:00
parent a9323376ec
commit c8fe27d6c4
5 changed files with 19 additions and 2 deletions

View File

@ -1192,6 +1192,9 @@ static void patchJump(Compiler* compiler, int offset)
// Parses a block body, after the initial "{" has been consumed.
static void finishBlock(Compiler* compiler)
{
// Empty blocks do nothing.
if (match(compiler, TOKEN_RIGHT_BRACE)) return;
for (;;)
{
definition(compiler);

View File

@ -1288,9 +1288,9 @@ void wrenDefineMethod(WrenVM* vm, const char* className,
double wrenGetArgumentDouble(WrenVM* vm, int index)
{
ASSERT(vm->nativeCallSlot != NULL, "Must be in foreign call.");
ASSERT(vm->foreignCallSlot != NULL, "Must be in foreign call.");
ASSERT(index >= 0, "index cannot be negative.");
ASSERT(index < vm->nativeCallNumArgs, "Not that many arguments.");
ASSERT(index < vm->foreignCallNumArgs, "Not that many arguments.");
// + 1 to shift past the receiver.
// TODO: Check actual value type first.

7
test/empty_block.wren Normal file
View File

@ -0,0 +1,7 @@
{} // By itself.
// In a statement.
if (true) {}
if (false) {} else {}
IO.write("ok") // expect: ok

View File

@ -0,0 +1,2 @@
var f = fn {}
IO.write(f.call) // expect: null

View File

@ -0,0 +1,5 @@
class Foo {
bar {}
}
IO.write((new Foo).bar) // expect: null