From 9d114b9707fd3d6aaa3224cd1794e8e49e433f36 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Sat, 11 Jul 2020 19:28:07 -0300 Subject: infer: Add type inference support for Union types This adds the type inference to Union types and add a small test case for it, ensuring it keeps working in future. Fixes: #5277 Signed-off-by: Otavio Salvador --- crates/ra_hir_ty/src/infer/expr.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_ty/src/infer/expr.rs') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 06baac2a9..bd9a387f5 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -405,8 +405,15 @@ impl<'a> InferenceContext<'a> { .subst(&a_ty.parameters) }) } - // FIXME: - TypeCtor::Adt(AdtId::UnionId(_)) => None, + TypeCtor::Adt(AdtId::UnionId(u)) => { + self.db.union_data(u).variant_data.field(name).map(|local_id| { + let field = FieldId { parent: u.into(), local_id }; + self.write_field_resolution(tgt_expr, field); + self.db.field_types(u.into())[field.local_id] + .clone() + .subst(&a_ty.parameters) + }) + } _ => None, }, _ => None, -- cgit v1.2.3