forked from Mirror/wren
Allow empty blocks.
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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
7
test/empty_block.wren
Normal file
@ -0,0 +1,7 @@
|
||||
{} // By itself.
|
||||
|
||||
// In a statement.
|
||||
if (true) {}
|
||||
if (false) {} else {}
|
||||
|
||||
IO.write("ok") // expect: ok
|
||||
2
test/function/empty_block.wren
Normal file
2
test/function/empty_block.wren
Normal file
@ -0,0 +1,2 @@
|
||||
var f = fn {}
|
||||
IO.write(f.call) // expect: null
|
||||
5
test/method/empty_block.wren
Normal file
5
test/method/empty_block.wren
Normal file
@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
bar {}
|
||||
}
|
||||
|
||||
IO.write((new Foo).bar) // expect: null
|
||||
Reference in New Issue
Block a user