Repository navigation
Compare two enum values as their element type - #691
Merged
Merged
Conversation
A comparison whose left operand was still an enum (a variable or parameter of the enum type, or `E | undefined`) had no case in the LLVM lowering: it warned "Not applicable logical operator for type: 'E'" and was constant false, `a == a` included. Only a comparison with a member (a literal) worked, as an integer. TSLANG_ISSUES.md: items 1-19 were fixed or answered and 20 is fixed here, so the file now lists nothing open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
A comparison whose left operand was still an enum, such as a variable or parameter of the enum type or
E | undefined, had no case in the LLVM lowering (LogicOpinUnaryBinLogicalOrHelper.h, where it was commented out). It fell through to the default: a warning, "Not applicable logical operator for type: 'E'", and a constantfalse.Comparing with a member (
held == Button.Right) worked only because the member is a literal, which MLIRGen turns into ansi32first.Fix
An enum operand is lowered as its element type: integers for numeric enums, a string compare for string enums.
E | undefinedalready unwraps into this path through the optional lowering, and so does a value narrowed by!== undefined. The "doesn't narrow" symptom in the report was this same bug.Tests
tslang/test/tester/tests/00enum_compare.ts, registered for compile and JIT runs (rc and none corpus runs pick it up too). It covers==/!=/<on enum parameters,E | undefinedvsE,E | undefinedvsE | undefined, string enums, and the originalheld == othercase from native_ts_graphics.ctest -C Release: 100% passed, 5798/5798 (3 disabled as before).Docs
TSLANG_ISSUES.md: items 1-19 were already fixed or answered, and 20 is fixed here. The file now says nothing is open and points to git history for the old write-ups.🤖 Generated with Claude Code