fix(parser): allow comments between a bare return and its terminator - #3
Merged
Conversation
A valueless `return` followed by a comment before the block terminator (`elseif`/`else`/`end`/`until`) failed to parse with "Expected expression". `parse_return/1` peeked at the raw next token to detect an empty return; a comment token is not a terminator, so it fell through to `parse_expr_list` and choked on the comment. Comments are whitespace in Lua, so peek past them (`skip_comments/1`) when deciding whether the return is bare. The comment tokens are left in the stream so the block parser still collects them as orphaned/trailing comments. Real Lua 5.3 and Luerl both accept this; the idiom shows up in `if ... then return -- note \n elseif ...` style branches. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
|
Filed upstream as well in tv-labs#418 |
Aratramba
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A valueless
returnfollowed by a comment before the block terminator (elseif/else/end/until) fails to parse:Real Lua 5.3 and Luerl both accept this — comments are whitespace, so the
returnis simply a bare (valueless) return and the branch continues. This is a common idiom (then return -- note \n elseif ...).Why it matters for us
This VM runs tenant Lua in production (engage journey engine) and in the
lua-devSDK. The bug surfaced viamake test-lua-app APP=healthpass, whosecore/init.luahas exactly this shape — the whole module failed to load, reported downstream as a misleadingattempt to concatenate a nil value.Root cause
Lua.Parser.parse_return/1peeked at the raw next token to decide whether thereturnwas valueless. A comment token isn't one of the terminators, so it fell through toparse_expr_list, which then choked on the comment → "Expected expression".Fix
Peek past comment tokens (
skip_comments/1) when detecting the terminator. The comment tokens stay in the stream, so the block parser still collects them as orphaned/trailing comments (no comment metadata is lost).Tests
test/lua/parser/statement_test.exscoveringreturn+ comment beforeelseif/else/end— fails before, passes after.mix test test/lua/parser/— 346 passedmix test(full suite) — 2638 passed, 7 skipped.luafiles now parse.🤖 Generated with Claude Code