Lower priority for speculative variadic tuple inferences#39723
Merged
ahejlsberg merged 3 commits intomasterfrom Jul 24, 2020
Merged
Lower priority for speculative variadic tuple inferences#39723ahejlsberg merged 3 commits intomasterfrom
ahejlsberg merged 3 commits intomasterfrom
Conversation
RyanCavanaugh
approved these changes
Jul 24, 2020
| NoConstraints = 1 << 7, // Don't infer from constraints of instantiable types | ||
| AlwaysStrict = 1 << 8, // Always use strict rules for contravariant inferences | ||
| MaxValue = 1 << 9, // Seed for inference priority tracking | ||
| SpeculativeTuple = 1 << 1, // Speculative tuple inference |
Member
There was a problem hiding this comment.
I think without the explanation, this is unclear.
| else if (middleLength === 1 && elementFlags[startLength] & ElementFlags.Variadic) { | ||
| // Middle of target is exactly one variadic element. Infer the slice between the fixed parts in the source. | ||
| inferFromTypes(isTupleType(source) ? sliceTupleType(source, startLength, sourceEndLength) : createArrayType(sourceRestType!), elementTypes[startLength]); | ||
| // If target ends in optional element(s), make a lower priority a speculative inference. |
Member
There was a problem hiding this comment.
If the documentation is going to be sparse on SpeculativeTuple, I think showing a concrete example here is worthwhile. Your explanation on the PR would be great.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR reverts #39281 and #39614 and instead implements the originally envisioned solution of giving higher priority to inferences made to
[...T, X]than inferences made to[...T, X?](because the latter speculates that the optional element is present). For example:Fixes #39253.