Skip to content

Panic when inferring repeated dynamic type() reassignment inside a loop #3627

@sunny-zuo

Description

@sunny-zuo

Summary

ty panics while type checking a function that repeatedly assigns a dynamically created type() object back to the same annotated local variable inside a loop. The issue was originally found in a test dynamically constructing nested Pydantic model classes and reproduces on ty 0.0.37 and 0.0.42.

Reproducer

Playground link.

def make_chain(depth: int) -> type[object]:
    current: type[object] = type("Leaf", (object,), {})
    for index in range(depth):
        current = type(f"Level{index}", (object,), {"child": current})
    return current

Behavior

fatal[panic] Panicked at .../salsa-0.26.2/src/function/execute.rs:633:9 when checking `repro.py`:
`infer_definition_types(Id(...)): execute: too many cycle iterations`

Found 1 diagnostic
WARN A fatal error occurred while checking some files. Not all project files were analyzed.

The non-loop variant does not cause a panic.

Version

ty 0.0.42

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfatala fatal error (panic or crash)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions