[ty] support recursive type aliases (#19805)

## Summary

Support recursive type aliases by adding a `Type::TypeAlias` type
variant, which allows referring to a type alias directly as a type
without eagerly unpacking it to its value.

We still unpack type aliases when they are added to intersections and
unions, so that we can simplify the intersection/union appropriately
based on the unpacked value of the type alias.

This introduces new possible recursive types, and so also requires
expanding our usage of recursion-detecting visitors in Type methods. The
use of these visitors is still not fully comprehensive in this PR, and
will require further expansion to support recursion in more kinds of
types (I already have further work on this locally), but I think it may
be better to do this incrementally in multiple PRs.

## Test Plan

Added some recursive type-alias tests and made them pass.
This commit is contained in:
Carl Meyer 2025-08-12 09:03:10 -07:00 committed by GitHub
parent d76fd103ae
commit 13bdba5d28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 542 additions and 150 deletions

View file

@ -243,6 +243,7 @@ impl<'db> Completion<'db> {
| Type::KnownInstance(_)
| Type::AlwaysTruthy
| Type::AlwaysFalsy => return None,
Type::TypeAlias(alias) => imp(db, alias.value_type(db))?,
})
}
imp(db, self.ty)