-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Stricter criteria for eliminating types in unions during inference #32919
Conversation
This PR slightly tweaks the conditions under which we eliminate types in unions during type inference. Specifically, it modifies the last bullet relating to union types in #32558 to be:
|
@typescript-bot run dt |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 6d46850. You can monitor the build here. It should now contribute to this PR's status checks. |
DT run is clean, I think this one is ready to merge. |
@ahejlsberg did you specifically want this one in 3.6.1? |
@@ -15905,7 +15901,7 @@ namespace ts { | |||
const symbol = isNonConstructorObject ? target.symbol : undefined; | |||
if (symbol) { | |||
if (contains(symbolStack, symbol)) { | |||
inferenceIncomplete = true; | |||
inferencePriority = -1; |
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.
I can't tell if -1
is being used here because it's lower than anything else, has all bits set, or both. A named enum member with the intended semantics of this would be clearer.
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.
It's because -1
is less than any normal priority value. I'll give it a symbolic name.
if (inferenceMatch) matched[i] = true; | ||
inferenceMatch = inferenceMatch || saveInferenceMatch; | ||
if (inferencePriority === priority) matched[i] = true; | ||
inferenceCircularity = inferenceCircularity || inferencePriority < 0; |
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.
Is it possible for inferencePriority
to be a negative value that isn't -1
?
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.
No
const saveInferenceIncomplete = inferenceIncomplete; | ||
inferenceMatch = false; | ||
inferenceIncomplete = false; | ||
(visited || (visited = createMap<number>())).set(key, -1); |
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.
Is the -1
here (used as number
) the same -1
lower in the file?
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.
Yes
I think it is a very safe fix, so yes if possible. |
@typescript-bot cherry-pick this into release-3.6 |
Hey @RyanCavanaugh, I've opened #32933 for you. |
Component commits: a81ce06 Stricter criteria for eliminating types in unions during inference f929a25 Add regression test 6d46850 Accept new baselines 86d9153 Accept new API baselines abc61a0 Add InferencePriority.Circularity per CR feedback ac2f151 Accept new API baselines c816cf2 Add additional test af7ccf9 Accept new baselines
Component commits: a81ce06 Stricter criteria for eliminating types in unions during inference f929a25 Add regression test 6d46850 Accept new baselines 86d9153 Accept new API baselines abc61a0 Add InferencePriority.Circularity per CR feedback ac2f151 Accept new API baselines c816cf2 Add additional test af7ccf9 Accept new baselines
Fixes #32752.