Skip to content
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

Merged
merged 8 commits into from
Aug 16, 2019

Conversation

ahejlsberg
Copy link
Member

Fixes #32752.

@ahejlsberg
Copy link
Member Author

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:

  • Finally, if there were source types from which no inferences or only lower priority inferences were made in the previous step, infer from a union of those source types to each naked type parameter in the target set. Give lower priority to these inferences if the target set contains more than one naked type parameter.

@ahejlsberg
Copy link
Member Author

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 15, 2019

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.

@ahejlsberg ahejlsberg added this to the TypeScript 3.6.1 milestone Aug 15, 2019
@ahejlsberg
Copy link
Member Author

DT run is clean, I think this one is ready to merge.

@RyanCavanaugh
Copy link
Member

@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;
Copy link
Member

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.

Copy link
Member Author

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;
Copy link
Member

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 ?

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@ahejlsberg
Copy link
Member Author

did you specifically want this one in 3.6.1?

I think it is a very safe fix, so yes if possible.

@RyanCavanaugh
Copy link
Member

@typescript-bot cherry-pick this into release-3.6

@typescript-bot
Copy link
Collaborator

Hey @RyanCavanaugh, I've opened #32933 for you.

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this pull request Aug 16, 2019
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
@ahejlsberg ahejlsberg merged commit 489abca into master Aug 16, 2019
@ahejlsberg ahejlsberg deleted the fix32752 branch August 16, 2019 17:56
RyanCavanaugh pushed a commit that referenced this pull request Aug 16, 2019
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression with await type extraction in strict mode
3 participants