Skip to content

Commit 1c622e9

Browse files
committed
Add cycle recovery for type aliases
1 parent 3ca40f7 commit 1c622e9

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

crates/ra_hir_ty/src/db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub trait HirDatabase: DefDatabase {
2222
fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
2323

2424
#[salsa::invoke(crate::lower::ty_query)]
25+
#[salsa::cycle(crate::lower::ty_recover)]
2526
fn ty(&self, def: TyDefId) -> Ty;
2627

2728
#[salsa::invoke(crate::lower::value_ty_query)]

crates/ra_hir_ty/src/lower.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Ty {
742742
TyDefId::TypeAliasId(it) => type_for_type_alias(db, it),
743743
}
744744
}
745+
746+
pub(crate) fn ty_recover(_db: &impl HirDatabase, _cycle: &[String], _def: &TyDefId) -> Ty {
747+
Ty::Unknown
748+
}
749+
745750
pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Ty {
746751
match def {
747752
ValueTyDefId::FunctionId(it) => type_for_fn(db, it),

crates/ra_hir_ty/src/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,6 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
21542154
}
21552155

21562156
#[test]
2157-
#[should_panic] // we currently can't handle this
21582157
fn recursive_type_alias() {
21592158
assert_snapshot!(
21602159
infer(r#"
@@ -2163,7 +2162,10 @@ type Foo = Foo;
21632162
type Bar = A<Bar>;
21642163
fn test(x: Foo) {}
21652164
"#),
2166-
@""
2165+
@r###"
2166+
[59; 60) 'x': {unknown}
2167+
[67; 69) '{}': ()
2168+
"###
21672169
)
21682170
}
21692171

0 commit comments

Comments
 (0)