Repository navigation
1 !== true is true, and a length merged with -1 keeps -1 - #425
Merged
Merged
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 the two bugs left open by #424.
1 !== trueand"a" !== 1were false===/!==between a boolean, a number and a string folds to a constant inadjustTypesForBinaryOp, but the operator still runs on the replacement operands. They were(result, true), so!==computedtrue !== true. Both operators now get(false, true):false === trueis false,false !== trueis true.The fold also missed operands typed
number(isIntOrIndexOrFloat()does not match!ts.number), soconst x: number = 1; x === truecoerced and was true.isNumericnow includesNumberType.A length merged with -1 returned 4294967295
canWideTypeWithoutDataLosstreatsindexas a signless integer, sosi32 -> indexcounts as lossless and the merge pickedindex, which holds an unsigned value. The newmergeIndexWithSignedIntmergesindex(or a signless integer) with a signed integer into a signed integer of at least 64 bits. It runs in:mergeType: return types, array literals ([p.length, -1])findBaseType: conditionals (c ? p.length : -1),??, generic type arguments inferred from several argumentscanCastFromToitself is unchanged, so overload resolution and argument passing are not affected.Decisions to check
si64, not TypeScript'snumber. That matches the existingu32 + s32 -> si64rule inmergeIntTypes.index:const p = "abc"; c ? p.length : -1folds the length to a signlessi32constant, which wrapped the same way. Side effect: a function returning a signlessi32binding (e.g.Date.getDate()) on one path and-1on another now inferssi64instead ofi32.index(32) + si32also becomessi64.Not in this PR
let x = p.length; x = -1;still prints 4294967295: the variable's type is fixed at its declaration, no merge happens.Tests
00strict_equals_mismatched_types.ts(literals, consts,number/boolean/string-typed values; loose==still coerces) and00length_with_negative_merge.ts(both return orders, conditionals, array literals, constant-string length), each compile + jit.🤖 Generated with Claude Code