1
0
forked from Mirror/wren

Allow variables without initializers.

This commit is contained in:
Bob Nystrom
2013-12-22 18:47:58 -08:00
parent 034fec6eaa
commit 3c8b4c009f
3 changed files with 15 additions and 4 deletions

View File

@ -1900,11 +1900,16 @@ void statement(Compiler* compiler)
// TODO: Variable should not be in scope until after initializer.
int symbol = declareVariable(compiler);
// TODO: Allow uninitialized vars?
consume(compiler, TOKEN_EQ, "Expect '=' after variable name.");
// Compile the initializer.
expression(compiler);
if (match(compiler, TOKEN_EQ))
{
expression(compiler);
}
else
{
// Default initialize it to null.
null(compiler, false);
}
defineVariable(compiler, symbol);
return;

View File

@ -0,0 +1,2 @@
var a
IO.write(a) // expect: null

View File

@ -0,0 +1,4 @@
{
var a
IO.write(a) // expect: null
}