From 90de08b8b650852f04c482d345c0d9f05c62f5da Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 16 Jul 2025 11:58:54 +0200 Subject: Codegen: Assert that function ends in return --- src/parser.pry | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/parser.pry') diff --git a/src/parser.pry b/src/parser.pry index 1e7ff56..54538b2 100644 --- a/src/parser.pry +++ b/src/parser.pry @@ -742,6 +742,14 @@ let parser_parse_function_definition = (p: *parser) => *Node { i = i + 1; }; + /* Validate that function has at least one statement and ends with return */ + if i == 0 { + return cast(*Node, null); + }; + let last_stmt = *(statements + cast(**Node, i - 1)); + if (*last_stmt).type != NODE_RETURN_STATEMENT { + return cast(*Node, null); + }; if parser_accept_token(p, TOKEN_RBRACE) == cast(*token, null) { return cast(*Node, null); -- cgit 1.4.1