aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2020-12-22 23:06:19 +0000
committerPhilip Herron <herron.philip@googlemail.com>2020-12-23 12:32:15 +0000
commita4e20cf765364221946200c8e7f96c2041f827a5 (patch)
treee193a083e8e9a462df3f6b17b1edd54878ec5b4a /gcc
parent04bcc692f53d9d0dd85f6c2b8d313e3f69ccf52d (diff)
downloadgcc-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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-tyty-resolver.h10
-rw-r--r--gcc/testsuite/rust.test/compilable/shadow1.rs5
-rw-r--r--gcc/testsuite/rust.test/fail_compilation/shadow1.rs6
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;
+}