aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-10-02 15:37:37 +0200
committerHimbeer <himbeer@disroot.org>2024-10-02 15:37:37 +0200
commit6dcaccdab64366d086898dc289fda9d80b98e636 (patch)
tree8da5292fc36b745885d10d715296ba101d54b750 /src
parent7c2cfd1657924a9d66757a627eef9caa117684a9 (diff)
Implement optional return expressions
This is the implementation of commit 7c2cfd1657924a9d66757a627eef9caa117684a9.
Diffstat (limited to 'src')
-rw-r--r--src/parse.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/parse.c b/src/parse.c
index 511cb18..3fa1498 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -1097,8 +1097,10 @@ parse_return(struct lexer *lexer, struct ast_return *out)
return false;
}
- if (!parse_expr(lexer, &out->value)) {
- error(lex_loc(lexer), "syntax error: expected expression");
+ out->value = must_malloc(sizeof(struct ast_expr));
+ if (!parse_expr(lexer, out->value)) {
+ free(out->value);
+ out->value = NULL;
}
return true;