Skip to content

Conversation

sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Sep 10, 2025

Summary

When adding an enum literal E = Literal[Color.RED] to a union which already contained a subtype of that enum literal(!), we were previously not simplifying the union correctly. My assumption is that our property tests didn't catch that earlier, because the only possible non-trivial subytpe of an enum literal that I can think of is Any & E. And in order for that to be detected by the property tests, it would have to randomly generate Any & E | E and then also compare that with E on the other side (in an equivalence test, or the subtyping-antisymmetry test).

closes astral-sh/ty#1155

Test Plan

  • Added a regression test.
  • I also ran the property tests for a while, but probably not for two months worth of daily CI runs.

@sharkdp sharkdp added the ty Multi-file analysis & type inference label Sep 10, 2025
Comment on lines -447 to -448
self.elements
.push(UnionElement::Type(Type::EnumLiteral(enum_member_to_add)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the problem. Instead of just using self.elements.push, we should go through the whole simplification logic in the _ => {…} branch, which I have now moved to a separate function. Every other change in this file is just the "moving out to a separate function" part.

Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@sharkdp sharkdp merged commit 57d1f71 into main Sep 10, 2025
39 checks passed
@sharkdp sharkdp deleted the david/fix-1155 branch September 10, 2025 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enum union and intersection with Any not simplifying correctly

2 participants