Repository navigation
Fix equality narrowing and comparable relation for intersections with {} - #50735
Conversation
|
TypeScript Bot (@typescript-bot) test this |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 7d9924d. You can monitor the build here. Update: The results are in! |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 7d9924d. You can monitor the build here. |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based top-repos suite on this PR at 7d9924d. You can monitor the build here. Update: The results are in! |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 7d9924d. You can monitor the build here. |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at 7d9924d. You can monitor the build here. Update: The results are in! |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user test suite comparing Everything looks good! |
|
Anders Hejlsberg (@ahejlsberg) Here they are:Comparison Report - main..50735
System
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top-repos suite comparing Everything looks good! |
|
TypeScript Bot (@typescript-bot) test this |
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 7d9924d. You can monitor the build here. |
|
Heya Anders Hejlsberg (@ahejlsberg), I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here. |
|
Tests and perf all look good. This one is ready to merge. |
|
Andrew Branch (@andrewbranch) Ping for review. |
| const constraints = sameMap((source as IntersectionType).types, getBaseConstraintOrType); | ||
| const constraints = sameMap((source as IntersectionType).types, t => t.flags & TypeFlags.Instantiable ? getBaseConstraintOfType(t) || unknownType : t); | ||
| if (constraints !== (source as IntersectionType).types) { | ||
| source = getIntersectionType(constraints); | ||
| if (source.flags & TypeFlags.Never) { | ||
| return Ternary.False; | ||
| } |
There was a problem hiding this comment.
Where do these changes come into play?
There was a problem hiding this comment.
From the comment right above:
// Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
// constraints of all non-primitive types in the source into a new intersection. We do this because the
// intersection may further constrain the constraints of the non-primitive types. For example, given a type
// parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
// appear to be comparable to '2'.The code previously didn't properly handle unconstrained type parameters, and it didn't properly handle the case where the hoisting causes the constraint to be never (meaning the types have no overlap).
|
TypeScript Bot (@typescript-bot) cherry-pick this to release-4.8 |
|
Heya Andrew Branch (@andrewbranch), I've started to run the task to cherry-pick this into |
commented
Sep 14, 2022
|
Hey Andrew Branch (@andrewbranch), I couldn't open a PR with the cherry-pick. (You can check the log here). You may need to squash and pick this PR into release-4.8 manually. |
This PR fixes both the original issue in #50706 and the issue reported here. It also fixes an issue in control flow analysis of the false branch of
!=(which should always yield the same result as the true branch of==, but didn't). Specifically, in this test,xwas wrongly narrowed tonumberin the last branch.Fixes #50706.