From a4e20cf765364221946200c8e7f96c2041f827a5 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 22 Dec 2020 23:06:19 +0000 Subject: Shadowing rules are done as part of name resolution. When a new name is defined the name resolver freezes the previous declartion such that all new references point to the latest decl. This patch fixes a crash when we shadow and get a type mismatch and the combination of types fails. See the failure test case for the crash. --- gcc/rust/typecheck/rust-tyty-resolver.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gcc/rust') diff --git a/gcc/rust/typecheck/rust-tyty-resolver.h b/gcc/rust/typecheck/rust-tyty-resolver.h index 1ee533e..b971e66 100644 --- a/gcc/rust/typecheck/rust-tyty-resolver.h +++ b/gcc/rust/typecheck/rust-tyty-resolver.h @@ -87,12 +87,18 @@ public: auto resolved_tyty = resolved_type; for (auto it : gathered_types) - resolved_tyty = resolved_tyty->combine (it); + { + auto combined = resolved_tyty->combine (it); + if (combined == nullptr) + break; + + resolved_tyty = combined; + } // something is not inferred we need to look at all references now if (resolved_tyty == nullptr || resolved_tyty->is_unit ()) { - rust_error_at (decl->get_locus_slow (), "failed to resolve type"); + rust_fatal_error (decl->get_locus_slow (), "failed to resolve type"); return false; } -- cgit v1.1