Skip to content

Commit

Permalink
Fixed a bug that resulted in a false positive when using heavily-nest…
Browse files Browse the repository at this point in the history
…ed call expressions that target overloads. The speculative type cache was not storing information about whether the type evaluation resulted in errors, so incorrect overloads were being chosen in the cached path. This addresses #4403.
  • Loading branch information
msfterictraut committed Jan 5, 2023
1 parent b78a9e4 commit b3f57ed
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 112 deletions.
12 changes: 7 additions & 5 deletions packages/pyright-internal/src/analyzer/typeCacheUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ interface SpeculativeContext {

export interface TypeResult {
type: Type;
isIncomplete: boolean;
isIncomplete?: boolean;
typeErrors?: boolean;
}

interface SpeculativeTypeEntry extends TypeResult {
interface SpeculativeTypeEntry {
typeResult: TypeResult;
expectedType: Type | undefined;
}

Expand Down Expand Up @@ -116,7 +118,7 @@ export class SpeculativeTypeTracker {
cacheEntries = [];
this._speculativeTypeCache.set(node.id, cacheEntries);
}
cacheEntries.push({ type: typeResult.type, isIncomplete: typeResult.isIncomplete, expectedType });
cacheEntries.push({ typeResult, expectedType });
}

getSpeculativeType(node: ParseNode, expectedType: Type | undefined): TypeResult | undefined {
Expand All @@ -130,10 +132,10 @@ export class SpeculativeTypeTracker {
for (const entry of entries) {
if (!expectedType) {
if (!entry.expectedType) {
return entry;
return entry.typeResult;
}
} else if (entry.expectedType && isTypeSame(expectedType, entry.expectedType)) {
return entry;
return entry.typeResult;
}
}
}
Expand Down
Loading

0 comments on commit b3f57ed

Please sign in to comment.