Make lower priority inferences when inference process is blocked
This commit is contained in:
parent
8f020559fb
commit
2450c1947f
1 changed files with 10 additions and 3 deletions
|
@ -15459,6 +15459,7 @@ namespace ts {
|
||||||
let bivariant = false;
|
let bivariant = false;
|
||||||
let propagationType: Type;
|
let propagationType: Type;
|
||||||
let inferenceCount = 0;
|
let inferenceCount = 0;
|
||||||
|
let inferenceBlocked = false;
|
||||||
let allowComplexConstraintInference = true;
|
let allowComplexConstraintInference = true;
|
||||||
inferFromTypes(originalSource, originalTarget);
|
inferFromTypes(originalSource, originalTarget);
|
||||||
|
|
||||||
|
@ -15655,6 +15656,7 @@ namespace ts {
|
||||||
if (source.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
|
if (source.flags & (TypeFlags.Object | TypeFlags.Intersection)) {
|
||||||
const key = source.id + "," + target.id;
|
const key = source.id + "," + target.id;
|
||||||
if (visited && visited.get(key)) {
|
if (visited && visited.get(key)) {
|
||||||
|
inferenceBlocked = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(visited || (visited = createMap<boolean>())).set(key, true);
|
(visited || (visited = createMap<boolean>())).set(key, true);
|
||||||
|
@ -15667,6 +15669,7 @@ namespace ts {
|
||||||
const symbol = isNonConstructorObject ? target.symbol : undefined;
|
const symbol = isNonConstructorObject ? target.symbol : undefined;
|
||||||
if (symbol) {
|
if (symbol) {
|
||||||
if (contains(symbolStack, symbol)) {
|
if (contains(symbolStack, symbol)) {
|
||||||
|
inferenceBlocked = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(symbolStack || (symbolStack = [])).push(symbol);
|
(symbolStack || (symbolStack = [])).push(symbol);
|
||||||
|
@ -15755,6 +15758,8 @@ namespace ts {
|
||||||
const sources = source.flags & TypeFlags.Union ? (<UnionType>source).types : [source];
|
const sources = source.flags & TypeFlags.Union ? (<UnionType>source).types : [source];
|
||||||
const matched = new Array<boolean>(sources.length);
|
const matched = new Array<boolean>(sources.length);
|
||||||
let typeVariableCount = 0;
|
let typeVariableCount = 0;
|
||||||
|
const saveInferenceBlocked = inferenceBlocked;
|
||||||
|
inferenceBlocked = false;
|
||||||
// First infer to types that are not naked type variables. For each source type we
|
// First infer to types that are not naked type variables. For each source type we
|
||||||
// track whether inferences were made from that particular type to some target.
|
// track whether inferences were made from that particular type to some target.
|
||||||
for (const t of target.types) {
|
for (const t of target.types) {
|
||||||
|
@ -15771,14 +15776,15 @@ namespace ts {
|
||||||
}
|
}
|
||||||
// If there are naked type variables in the target, create a union of the source types
|
// If there are naked type variables in the target, create a union of the source types
|
||||||
// from which no inferences have been made so far and infer from that union to each naked
|
// from which no inferences have been made so far and infer from that union to each naked
|
||||||
// type variable. If there is more than one naked type variable, give lower priority to
|
// type variable. If there is more than one naked type variable, or if inference was blocked
|
||||||
// the inferences as they are less specific.
|
// (meaning we didn't explore the types fully), give lower priority to the inferences as
|
||||||
|
// they are less specific.
|
||||||
if (typeVariableCount > 0) {
|
if (typeVariableCount > 0) {
|
||||||
const unmatched = flatMap(sources, (s, i) => matched[i] ? undefined : s);
|
const unmatched = flatMap(sources, (s, i) => matched[i] ? undefined : s);
|
||||||
if (unmatched.length) {
|
if (unmatched.length) {
|
||||||
const s = getUnionType(unmatched);
|
const s = getUnionType(unmatched);
|
||||||
const savePriority = priority;
|
const savePriority = priority;
|
||||||
if (typeVariableCount > 1) {
|
if (typeVariableCount > 1 || inferenceBlocked) {
|
||||||
priority |= InferencePriority.NakedTypeVariable;
|
priority |= InferencePriority.NakedTypeVariable;
|
||||||
}
|
}
|
||||||
for (const t of target.types) {
|
for (const t of target.types) {
|
||||||
|
@ -15789,6 +15795,7 @@ namespace ts {
|
||||||
priority = savePriority;
|
priority = savePriority;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
inferenceBlocked = saveInferenceBlocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
function inferToMappedType(source: Type, target: MappedType, constraintType: Type): boolean {
|
function inferToMappedType(source: Type, target: MappedType, constraintType: Type): boolean {
|
||||||
|
|
Loading…
Reference in a new issue