From 7c423f5b88f40da4f3682602bf17a9b6848f5411 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 15 May 2021 21:30:40 +0200 Subject: Fix panic --- crates/hir_ty/src/infer/unify.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty/src/infer/unify.rs') diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index d8edfb4e9..259feecf1 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -149,7 +149,9 @@ impl TypeVariableTable { fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty { match kind { - _ if self.inner[iv.index() as usize].diverging => TyKind::Never, + _ if self.inner.get(iv.index() as usize).map_or(false, |data| data.diverging) => { + TyKind::Never + } TyVariableKind::General => TyKind::Error, TyVariableKind::Integer => TyKind::Scalar(Scalar::Int(IntTy::I32)), TyVariableKind::Float => TyKind::Scalar(Scalar::Float(FloatTy::F64)), @@ -205,6 +207,7 @@ impl<'a> InferenceTable<'a> { fn new_var(&mut self, kind: TyVariableKind, diverging: bool) -> Ty { let var = self.var_unification_table.new_variable(UniverseIndex::ROOT); // Chalk might have created some type variables for its own purposes that we don't know about... + // TODO refactor this? self.type_variable_table.inner.extend( (0..1 + var.index() as usize - self.type_variable_table.inner.len()) .map(|_| TypeVariableData { diverging: false }), -- cgit v1.2.3