[ty] Fix subtyping for dynamic specializations (#20592)

## Summary

Fixes a bug observed by @AlexWaygood where `C[Any] <: C[object]` should
hold for a class that is covariant in its type parameter (and similar
subtyping relations involving dynamic types for other variance
configurations).

## Test Plan

New and updated Markdown tests
This commit is contained in:
David Peter 2025-09-26 15:05:03 +02:00 committed by GitHub
parent 2af8c53110
commit 3932f7c849
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 32 deletions

View file

@ -841,18 +841,6 @@ impl<'db> Specialization<'db> {
.zip(self.types(db))
.zip(other.types(db))
{
// As an optimization, we can return early if either type is dynamic, unless
// we're dealing with a top or bottom materialization.
if other_materialization_kind.is_none()
&& self_materialization_kind.is_none()
&& (self_type.is_dynamic() || other_type.is_dynamic())
{
match relation {
TypeRelation::Assignability => continue,
TypeRelation::Subtyping => return ConstraintSet::from(false),
}
}
// Subtyping/assignability of each type in the specialization depends on the variance
// of the corresponding typevar:
// - covariant: verify that self_type <: other_type