[ty] Make tuple intersection a fallible operation#22094
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
| let Some(intersected) = builder.intersect(db, &spec) else { | ||
| // The intersection is impossible (e.g., two fixed-length tuples | ||
| // with different lengths). Treat similarly to `Never`. | ||
| return Some(Cow::Owned(TupleSpec::homogeneous(Type::unknown()))); | ||
| }; |
There was a problem hiding this comment.
theoretically this "should" always be Some(), because two tuples cannot have disjoint tuplespecs unless the tuples themselves are disjoint, and two disjoint tuple types cannot coexist in an intersection -- our IntersectionBuilder "should" eagerly simplify an intersection containing disjoint types to Never.
So on that basis, we "should" be able to call .expect() here rather than doing let Some(intersected) = builder.intersect(db, &spec) else {...}.
But I would need to do some work to double-check that we really do uphold those invariants in the ways that we should before I would confidently advise you to change this to a .expect() 😆
For now, it might be worth adding a comment reflecting this
52cc456 to
d30a573
Compare
Summary
This PR attempts to address a TODO in #21965 (comment).