Repository navigation
A for condition that tests an optional value is made a boolean - #510
Merged
Merged
Conversation
`for (let node = head; node; node = node.next)` with `node: Node | undefined` failed module verification under every memory model: 'ts.Condition' op operand #0 must be , but got '!ts.optional<...>'. mlirGen(ForStatement) handed the condition to ts.Condition as it was, while mlirGen(WhileStatement), mlirGen(DoStatement) and mlirGen(IfStatement) cast a non-boolean condition to boolean first. The for condition now goes through the same cast. `node !== undefined` was already boolean, which is why it worked. 00for_optional_class_condition.ts: a for over an optional class (in main and in a function), a nullable (`| null`) class and an optional string, next to the same test in while and if. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 5, 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.
for (let node = head; node; node = node.next)withnode: Node | undefinedfailed module verification under every memory model:mlirGen(ForStatement)passed the condition tots.Conditionunchanged.mlirGen(WhileStatement),mlirGen(DoStatement)andmlirGen(IfStatement)cast a non-boolean condition to boolean first. Theforcondition now goes through the same cast.node !== undefinedalready produced a boolean, which is why that form worked.Test
00for_optional_class_condition.tsruns aforover an optional class (inmainand in a function), over a nullable (| null) class and over an optional string, and runs the same tests withwhileandif. It is registered for compile and JIT and inTSLANG_CORPUS(rc and none). On main it fails to compile with the error above.ctest -C Release: 3858/3858 passed. gtest unittests were not built in this build tree.Not covered here
""is truthy in every condition (if,while,!,?:), filed as An empty string "" is truthy in if / while / ! / ?: conditions #509.-mm=ownrejects this list traversal ("borrows a field and cannot be stored"), with or without this fix and withnode !== undefinedtoo, so the test is not registered under own.whilenarrows the tested variable in its body (checkSafeCast);forstill does not. Nothing in this test needs it.🤖 Generated with Claude Code