Stricter criteria for eliminating types in unions during inference#32919
Stricter criteria for eliminating types in unions during inference#32919ahejlsberg merged 8 commits intomasterfrom
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? |
src/compiler/checker.ts
Outdated
| if (symbol) { | ||
| if (contains(symbolStack, symbol)) { | ||
| inferenceIncomplete = true; | ||
| inferencePriority = -1; |
There was a problem hiding this comment.
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.
It's because -1 is less than any normal priority value. I'll give it a symbolic name.
src/compiler/checker.ts
Outdated
| 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.
Is it possible for inferencePriority to be a negative value that isn't -1 ?
src/compiler/checker.ts
Outdated
| const saveInferenceIncomplete = inferenceIncomplete; | ||
| inferenceMatch = false; | ||
| inferenceIncomplete = false; | ||
| (visited || (visited = createMap<number>())).set(key, -1); |
There was a problem hiding this comment.
Is the -1 here (used as number) the same -1 lower in the file?
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.