Repository navigation
Preserve short-circuited call results in and expressions - #553
Open
skyon0522-ai wants to merge 1 commit into
Open
skyon0522-ai wants to merge 1 commit into
skyon0522-ai wants to merge 1 commit into
Conversation
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.
Fixes #490.
When
result = result and (first() and second())short-circuits becausefirst()returns false, the compiler can leave the previous value inresult. The issue's example returnstruefrom the helper-call version while the direct-comparison version returnsfalse. 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:
TESTSETpath for a computed operand when anandbranch exits the expression, so its false or nil value reaches the result register before the jump.Validation on revision
75f497656b1c6864139dd2a7d88cf96d09550814with this patch:make build,go test -mod=readonly ./..., andgit diff --checkpassed.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.