Allow returns without an explicit value.

This commit is contained in:
Bob Nystrom
2014-01-12 19:37:11 -08:00
parent cf623844c4
commit 8e8bb4b9b9
5 changed files with 28 additions and 6 deletions
+9 -4
View File
@@ -1828,7 +1828,6 @@ void namedSignature(Compiler* compiler, char* name, int* length)
if (match(compiler, TOKEN_EQ))
{
// It's a setter.
// TODO: Allow setters with parameters? Like: foo.bar(1, 2) = "blah"
name[(*length)++] = '=';
name[(*length)++] = ' ';
@@ -2326,9 +2325,15 @@ void statement(Compiler* compiler)
if (match(compiler, TOKEN_RETURN))
{
// Compile the return value.
// TODO: Implicitly return null if there is a newline or } after the
// "return".
expression(compiler);
if (peek(compiler) == TOKEN_LINE || peek(compiler) == TOKEN_RIGHT_BRACE)
{
// Implicitly return null if there is no value.
emit(compiler, CODE_NULL);
}
else
{
expression(compiler);
}
emit(compiler, CODE_RETURN);
return;