Add support to return void in a function

* statement `return;` is valid now.
* functions return void by default, an explicit return is not necessary now
This commit is contained in:
Skydark Chen committed 2015-11-15 19:44:02 +08:00
1 parent 33c2bd0c94
commit 2924666ad4
2 files changed
+5 -1

No files matched your search

@@ -26,7 +26,10 @@ public abstract class Statement {
}
case T_RETURN: {
parser.next();
ParsedExpression expression = ParsedExpression.read(parser, environment);
ParsedExpression expression = null;
if (parser.peek() != null && !parser.isNext(T_SEMICOLON)) {
expression = ParsedExpression.read(parser, environment);
}
parser.required(T_SEMICOLON, "; expected");
return new StatementReturn(next.getPosition(), returnType, expression);
}