diff options
author | Philip Herron <philip.herron@embecosm.com> | 2020-12-22 23:06:19 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2020-12-23 12:32:15 +0000 |
commit | a4e20cf765364221946200c8e7f96c2041f827a5 (patch) | |
tree | e193a083e8e9a462df3f6b17b1edd54878ec5b4a | |
parent | 04bcc692f53d9d0dd85f6c2b8d313e3f69ccf52d (diff) | |
download | gcc-a4e20cf765364221946200c8e7f96c2041f827a5.zip gcc-a4e20cf765364221946200c8e7f96c2041f827a5.tar.gz gcc-a4e20cf765364221946200c8e7f96c2041f827a5.tar.bz2 |
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.
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-resolver.h | 10 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/compilable/shadow1.rs | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust.test/fail_compilation/shadow1.rs | 6 |
3 files changed, 19 insertions, 2 deletions
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; } diff --git a/gcc/testsuite/rust.test/compilable/shadow1.rs b/gcc/testsuite/rust.test/compilable/shadow1.rs new file mode 100644 index 0000000..3cb1ec5 --- /dev/null +++ b/gcc/testsuite/rust.test/compilable/shadow1.rs @@ -0,0 +1,5 @@ +fn main() { + let mut x = 5; + let mut x; + x = true; +} diff --git a/gcc/testsuite/rust.test/fail_compilation/shadow1.rs b/gcc/testsuite/rust.test/fail_compilation/shadow1.rs new file mode 100644 index 0000000..18c5c58 --- /dev/null +++ b/gcc/testsuite/rust.test/fail_compilation/shadow1.rs @@ -0,0 +1,6 @@ +fn main() { + let mut x = 5; + let mut x; + x = true; + x = x + 2; +} |