-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix equality narrowing and comparable relation for intersections with {} #50735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@typescript-bot test this |
Heya @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 @ahejlsberg, I've started to run the extended test suite on this PR at 7d9924d. You can monitor the build here. |
Heya @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 @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 7d9924d. You can monitor the build here. |
Heya @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! |
@ahejlsberg Here are the results of running the user test suite comparing Everything looks good! |
@ahejlsberg Here they are:Comparison Report - main..50735
System
Hosts
Scenarios
Developer Information: |
@ahejlsberg Here are the results of running the top-repos suite comparing Everything looks good! |
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 7d9924d. You can monitor the build here. |
Heya @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. |
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do these changes come into play?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 cherry-pick this to release-4.8 |
Heya @andrewbranch, I've started to run the task to cherry-pick this into |
Hey @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,x
was wrongly narrowed tonumber
in the last branch.Fixes #50706.