Add cycle recovery for type aliases

This commit is contained in:
Florian Diebold 2019-11-30 12:48:51 +01:00
parent 3ca40f7c08
commit 1c622e9fed
3 changed files with 10 additions and 2 deletions

View file

@ -22,6 +22,7 @@ pub trait HirDatabase: DefDatabase {
fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
#[salsa::invoke(crate::lower::ty_query)]
#[salsa::cycle(crate::lower::ty_recover)]
fn ty(&self, def: TyDefId) -> Ty;
#[salsa::invoke(crate::lower::value_ty_query)]

View file

@ -742,6 +742,11 @@ pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Ty {
TyDefId::TypeAliasId(it) => type_for_type_alias(db, it),
}
}
pub(crate) fn ty_recover(_db: &impl HirDatabase, _cycle: &[String], _def: &TyDefId) -> Ty {
Ty::Unknown
}
pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty {
match def {
ValueTyDefId::FunctionId(it) => type_for_fn(db, it),

View file

@ -2154,7 +2154,6 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
}
#[test]
#[should_panic] // we currently can't handle this
fn recursive_type_alias() {
assert_snapshot!(
infer(r#"
@ -2163,7 +2162,10 @@ type Foo = Foo;
type Bar = A<Bar>;
fn test(x: Foo) {}
"#),
@""
@r###"
[59; 60) 'x': {unknown}
[67; 69) '{}': ()
"###
)
}