diff options
| author | Baitinq <[email protected]> | 2025-07-16 11:58:54 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-07-16 11:58:54 +0200 |
| commit | 90de08b8b650852f04c482d345c0d9f05c62f5da (patch) | |
| tree | 5ff9aa4a63bac873a4a8fa7824f090c6da0eacc8 /src | |
| parent | Feature: Implement and/or short circuiting (diff) | |
| download | pry-lang-90de08b8b650852f04c482d345c0d9f05c62f5da.tar.gz pry-lang-90de08b8b650852f04c482d345c0d9f05c62f5da.tar.bz2 pry-lang-90de08b8b650852f04c482d345c0d9f05c62f5da.zip | |
Codegen: Assert that function ends in return
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.pry | 8 |
1 files changed, 8 insertions, 0 deletions
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); |