Skip to content

Type alias statements stop tracking typevar variance after two deep #3518

@MeGaGiGaGon

Description

@MeGaGiGaGon

Summary

Ran into this while making my umpteenth generic parser generator soup and messed up a parser generator transformer.
https://play.ty.dev/d0fab0ef-bf5d-496f-b305-046e604cd702

from dataclasses import dataclass

@dataclass
class Box[T]:  # T is invariant
    item: T

type RefBox[T] = Box[T]  # T is invariant
type RefRefBox[T] = RefBox[T]  # T is bivariant???

When combined with #3517, you can make a type safe transmute (this happened in my actual code):
https://play.ty.dev/eff23d78-ef4e-4bda-8aa7-b9848e527cb3

Version

ty 0.0.35 (bc12d1c 2026-05-10) playground 7efc9a6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions