Skip to content

Preserve short-circuited call results in and expressions - #553

Open
skyon0522-ai wants to merge 1 commit into
yuin:masterfrom
skyon0522-ai:fix-short-circuit-call-results-490-20261023
Open

skyon0522-ai wants to merge 1 commit into
yuin:masterfrom
skyon0522-ai:fix-short-circuit-call-results-490-20261023

Conversation

@skyon0522-ai

Copy link
Copy Markdown

Fixes #490.

When result = result and (first() and second()) short-circuits because first() returns false, the compiler can leave the previous value in result. The issue's example returns true from the helper-call version while the direct-comparison version returns false. This change preserves the short-circuited value in the assignment destination, as required by Lua 5.1's logical-operator semantics.

Changes proposed in this pull request:

  • Use the existing TESTSET path for a computed operand when an and branch exits the expression, so its false or nil value reaches the result register before the jump.
  • Add a regression test for helper-call comparisons below, at, inside, and above the bounds. It fails before the fix and passes afterward.

Validation on revision 75f497656b1c6864139dd2a7d88cf96d09550814 with this patch:

  • Focused regression: failing before, passing after; the original example and five boundary inputs were also checked through an external API host.
  • make build, go test -mod=readonly ./..., and git diff --check passed.
  • go vet -mod=readonly ./... reports six diagnostics (self-assignment and unreachable code). The unmodified revision produces the same six diagnostics with the same toolchain.

Checks used Go 1.27.2 on Linux/amd64. This is outside the repository's Go 1.24/1.25 CI matrix; those versions and other platforms were not run locally.

Prepared and checked with OpenAI Codex assistance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extra PC increment in JMP instruction

1 participant