Repository navigation
@cpp class | null tested for truth with a boolean (h && cond): no instanceof - #765
Open
ASDAlexander77 wants to merge 1 commit into
Open
ASDAlexander77 wants to merge 1 commit into
ASDAlexander77 wants to merge 1 commit into
Conversation
…nger asks instanceof `h && n == 3` with h a `Handle | null` (@cpp) is a union of the class, null and boolean; castFromUnion's ___cast helper tested each class member with instanceof, which a @cpp class refuses (its objects carry no type info). When the class need not be told apart - the only class of the union, or the union tested for truth - typeof has narrowed t enough: `return t`. Otherwise only the non-@cpp classes are tested. TSLANG_ISSUES 23. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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 TSLANG_ISSUES 23:
if (h && n == 3)withha@cppclass| nullfailed with "instanceof can't be used with a @cpp class" and "'___cast' not all generic types can be identified".h && n == 3is typedHandle | null | boolean; making it a boolean goes throughcastFromUnion, whose generated___casttests every class member withinstanceof, which a@cppclass refuses (its objects are C++ objects with no type information).writeClassTestslambda (used by the null-target and default branches).@cppclass and the class need not be told apart (the only class of the union, or tested for truth), it emitsreturn t;:typeofhas narrowedtenough, and truthiness is the null test.instanceofis emitted only for the non-@cppclasses.Test:
tests/00cpp_union_truth.ts(hand-made C++ object):h && n == 3,enabled && hwith a handle and null, and two@cppclasses in a union with a boolean tested for truth. Registered compile/JIT default + own, and in the rc/none corpus. Full release ctest passes.Issue 22 (one-field
@valueT | null) was already fixed by #763; checked with the current build.🤖 Generated with Claude Code