'return' is now a valid statement outside of a function

lets us do some cool things later. also the repl can print returned values. eg.

`return "hello world"` will print `<string> "hello world"` to the console
This commit is contained in:
2023-12-28 23:41:10 -06:00
parent 43d79a456e
commit e0455902b0
2 changed files with 16 additions and 4 deletions

View File

@@ -1471,10 +1471,10 @@ static void functionDeclaration(CParseState *pstate)
static void returnStatement(CParseState *pstate)
{
if (pstate->compiler->type != FTYPE_FUNCTION && pstate->compiler->type != FTYPE_METHOD) {
error(pstate, "Expected 'return' in function!");
return;
}
// if (pstate->compiler->type != FTYPE_FUNCTION && pstate->compiler->type != FTYPE_METHOD) {
// error(pstate, "Expected 'return' in function!");
// return;
// }
if (blockFollow(pstate->current)) { // does this return have a value
writeu8(pstate, OP_NIL);