Repository navigation
instanceof with a primitive value on the right is an error - #585
Merged
Merged
Conversation
`5 instanceof 3` compiled with no diagnostic: with no class on the right, the test compared the two types and was a constant. TypeScript rejects a right-hand side that is no class or function; tslang now rejects a number, string, boolean or bigint value there, at the right operand. A type on the right (`type str = TypeOf<"">`, as in tests/00instanceof.ts) stays an extension that compares the types. 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.
5 instanceof 3compiled with no diagnostic. With no class on the right,mlirGenInstanceOfLogicfell through to comparing the two types, giving a constant.Fix: a number, string, boolean or bigint value on the right of
instanceofis an error at the right operand.Repro (
diagnostic-location/instanceof_primitive.ts):Kept on purpose: a type on the right (
"asd" instanceof str,tests/00instanceof.ts). It is ats.TypeRef, and the test still compares the types. Line 7 of the test must stay error-free.Not changed: a primitive on the left (
5 instanceof C). TypeScript rejects it, but in a generic specialised for a number the left is a number legitimately, so it needs the unspecialised type to check.ctest -C Release -j 8 --timeout 300: 100% passed, 0 failed (4092 tests on this branch).🤖 Generated with Claude Code