mirror of https://github.com/astral-sh/ruff
## Summary This fixes https://github.com/astral-sh/ty/issues/1736 where recursive generic protocols with growing specializations caused a stack overflow. The issue occurred with protocols like: ```python class C[T](Protocol): a: 'C[set[T]]' ``` When checking `C[set[int]]` against e.g. `C[Unknown]`, member `a` requires checking `C[set[set[int]]]`, which requires `C[set[set[set[int]]]]`, etc. Each level has different type specializations, so the existing cycle detection (using full types as cache keys) didn't catch the infinite recursion. This fix adds a simple recursion depth limit (64) to the CycleDetector. When the depth exceeds the limit, we return the fallback value (assume compatible) to safely terminate the recursion. This is a bit of a blunt hammer, but it should be broadly effective to prevent stack overflow in any nested-relation case, and it's hard to imagine that non-recursive nested relation comparisons of depth > 64 exist much in the wild. ## Test Plan Added mdtest. |
||
|---|---|---|
| .. | ||
| module_resolver | ||
| semantic_index | ||
| types | ||
| ast_node_ref.rs | ||
| db.rs | ||
| diagnostic.rs | ||
| dunder_all.rs | ||
| lib.rs | ||
| lint.rs | ||
| list.rs | ||
| module_name.rs | ||
| node_key.rs | ||
| place.rs | ||
| program.rs | ||
| pull_types.rs | ||
| python_platform.rs | ||
| rank.rs | ||
| semantic_index.rs | ||
| semantic_model.rs | ||
| site_packages.rs | ||
| subscript.rs | ||
| suppression.rs | ||
| types.rs | ||
| unpack.rs | ||