Skip to content
TheChatArchiveThe Chat Archive
gpt-5.6-sol· openaiHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

Type alias statements stop tracking typevar variance after two deep Summary Ran into…

  1. User

    Type alias statements stop tracking typevar variance after two deep

    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 7efc9a615

    Evaluation contract

    Variance inference for both PEP 695 and legacy generic type aliases must recurse through the alias value rather than treating every alias as bivariant. Preserve covariant, contravariant, invariant, and bivariant results through multi-level and reordered multi-parameter alias chains. Recursive or mutually recursive alias cycles must terminate safely using the existing bivariant cycle fallback.

    Interface

    No new interfaces are introduced.

  2. Assistant

    I’m using the working-on-ty skill because this is a ty semantic inference bug. I’ll trace the existing variance machinery, add focused alias-chain and cycle coverage, implement the narrow fix, then run the prescribed tests and hooks.

  3. Assistant

    The fault is localized: variance traversal explicitly returns bivariant for the lazy Type::TypeAlias representation, even though the runtime TypeAliasType object already traverses its raw value. I’m checking cycle-query patterns before changing that branch so recursive aliases retain the intended safe fallback.

  4. Assistant

    The focused test build is underway. I added coverage for all four variance kinds through a second alias layer, reordered two-parameter chains, and a PEP 695 alias passing through two legacy generic aliases; the implementation routes lazy aliases through a Salsa-tracked query with bivariant cycle recovery.

  5. Assistant

    The first pass passes, including a mutually recursive case. One subtle recursion hazard remains: directly expanding a specialized recursive alias can create ever-growing keys such as Alias[list[T]]. I’m tightening the implementation to infer the unspecialized alias once and compose that result with its specialization, matching the generic-class variance algorithm and ensuring Salsa’s cycle fallback always sees a stable key.

  6. Assistant

    The complete ty_python_semantic suite now passes: 203 unit tests, 14 corpus tests, 338 mdtests, and doctests. No pending snapshots appeared in the focused run; I’m doing the repository-required hook pass and final diff review now.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.