Skip to content

Commit

Permalink
Added protection for an internal call stack overflow when inferring r…
Browse files Browse the repository at this point in the history
…eturn types in deep call hierarchies within untyped code. This addresses #9283. (#9346)
  • Loading branch information
erictraut authored Oct 28, 2024
1 parent bd766f8 commit 2ffc5f1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19229,6 +19229,20 @@ export function createTypeEvaluator(
}

writeTypeCache(node.d.suite, { type: inferredReturnType, isIncomplete }, EvalFlags.None);
} catch (err) {
// Attempt to handle a stack overflow without crashing. In rare
// cases, we can get very deep stacks when inferring return types
// within untyped code.
if ((err as any)?.message === 'Maximum call stack size exceeded') {
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
console.error(
`Overflowed stack when inferring return type for function: ${
node.d.name.d.value
} in file ${fileInfo.fileUri.toUserVisibleString()}`
);
return;
}
throw err;
} finally {
functionRecursionMap.delete(node.id);
}
Expand Down

0 comments on commit 2ffc5f1

Please sign in to comment.