Skip to content
TheChatArchiveThe Chat Archive
x-ai/grok-4.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Type alias statements stop tracking typevar variance after two deep…

  1. User

    ISSUE DESCRIPTION

    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.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /ruff, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository structure and locating the variance-tracking logic for type aliases.

  3. Assistant

    Searching for variance inference code related to type aliases.

  4. Assistant

    rg is not available, let me use grep.

  5. Assistant

    Let me look at the variance.rs file and type alias related code.

  6. Assistant

    Reading the type alias variance tests and variance implementation.

  7. Assistant

    Let me look at how variance is computed for generic contexts and type aliases.

  8. Assistant

    Found a likely culprit: TypeAlias appears to always return bivariant. Reading the full variance_of implementation.

  9. Assistant

    Let me see lines around 6870 more carefully.

  10. Assistant

    Checking how KnownInstance and specialized aliases compute variance, and reviewing related tests.

  11. Assistant

    Inspecting TypeAliasType value methods and how specialized aliases are represented.

  12. Assistant

    Checking variance for recursive aliases and cycle handling.

  13. Assistant

    Checking how cycle recovery works for variance computation.

  14. Assistant

    I need to understand how nested type-alias references appear in the type graph and whether cycle detection is required.

  15. Assistant

    Reading the variance and alias mdtests for expected behavior.

  16. Assistant

    Checking how specialized type aliases appear when nested, and inspecting the NewType path.

  17. Assistant

    Checking legacy type alias variance handling.

  18. Assistant

    Legacy type aliases via TypeAlias annotation are actually just type assignments - the type gets stored as the RHS type directly rather than Type::TypeAlias. Looking at:

  19. Assistant

    Let me read the type aliases section of pep695 variance.md fully.

  20. Assistant

    How does Type::TypeAlias participate in subtype relations?

  21. Assistant

    Checking how typevar variance is computed for type aliases.

  22. Assistant

    Checking default specialization and whether salsa tracked methods can be on enums.

  23. Assistant

    I'll implement VarianceInferable for PEP695TypeAliasType and ManualPEP695TypeAliasType with cycle_initial Bivariant, andWIRE Type::TypeAlias and KnownInstance to use them.

  24. Assistant

    Checking how subtyping of specialized type aliases uses variance of the alias's typevars.

  25. Assistant

    Checking how specialization applies to nested Type::TypeAlias values.

  26. Assistant

    Looking for contextroom around issue #3517 and any incomplete performance.

  27. Assistant

    Implementing VarianceInferable on type aliases with cycle-safe recursion.

  28. Assistant

    Implementing the fix now.

  29. Assistant

    Now I need to find where PEP695 methods end and add VarianceInferable impl.

  30. Assistant

    I'll add VarianceInferable after the PEP695 block (after line 148) and after ManualPEP695 block.

  31. Assistant

    Now add VarianceInferable for Manual and TypeAliasType enum.

  32. Assistant

    Now add VarianceInferable for TypeAliasType enum. I'll add it after the enum互换 impl block.

  33. Assistant

    I'll add VarianceInferable for TypeAliasType after the TypeAliasType impl.

  34. Assistant

    Now update Type::TypeAlias variance and KnownInstance.

  35. Assistant

    Now update KnownInstance to use type_alias.variance_of.

  36. Assistant

    Oops, I left an extra }. Fixing that.

  37. Assistant

    Need to check if BoundTypeVarInstance and VarianceInferable are imported ink known_instance.rs.

  38. Assistant

    Checking that VarianceInferable is in scopein types.rs:

  39. Assistant

    Extending the unit test for nested alias variance, then compiling and testing.

  40. Assistant

    I need to add the assertions for nested aliases. Also extend get_bound_typevar to support multi-parameter if needed.

  41. Assistant

    I need to update all the get_bound_typevar calls to pass index 0, and add nested assertions.

  42. Assistant

    I shouldn't modify existing tests. Restoring the test file and using a temporary script instead.

  43. Assistant

    Compiling and running the varianceand type-alias tests.

  44. Assistant

    Existing unit test passed. Writing a temporary test for nested aliases.

  45. Assistant

    I'll adda temporary test and then remove it. Or better - create tempfile mdtestadaptive.

  46. Assistant

    Need BoundTypeVarInstance importin tests. Checking the imports top of tests.rs.

  47. Assistant

    super::* should include BoundTypeVarInstance. Let me run the test.

  48. Assistant

    Nested cases pass. Removing the temp test and running the variance mdtests.

  49. Assistant

    All variance tests pass. Reproducing the issue via a temporary mdtest.

  50. Assistant

    Tidying up the temporary mdtest and verifying the finaldiff.

  51. Assistant

    Running a broader regression around aliases and cycles.

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