Skip to content

Commit 7651217

Browse files
committed
gccrs: Fix SEGV when type path resolver fails outright
When we resolve paths we resolve to Types first we walk each segment to the last module which has no type but then in the event that the child of a module is not found we have a null root_tyty which needs to be caught and turned into an ErrorType node. Fixes #3613 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): catch nullptr root_tyty gcc/testsuite/ChangeLog: * rust/compile/issue-3613.rs: New test. Signed-off-by: Philip Herron <[email protected]>
1 parent 1d93ebb commit 7651217

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

gcc/rust/typecheck/rust-hir-type-check-type.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset,
360360
seg->as_string ().c_str ());
361361
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
362362
}
363+
else if (root_tyty == nullptr)
364+
{
365+
rust_error_at (seg->get_locus (),
366+
"unknown reference for resolved name: %qs",
367+
seg->as_string ().c_str ());
368+
return new TyTy::ErrorType (path.get_mappings ().get_hirid ());
369+
}
363370
return root_tyty;
364371
}
365372

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mod m1 {
2+
pub enum Baz4 {
3+
foo1,
4+
foo2,
5+
}
6+
}
7+
8+
fn bar(x: m1::foo) {
9+
// { dg-error "unknown reference for resolved name: .foo." "" { target *-*-* } .-1 }
10+
match x {
11+
m1::foo::foo1 => {}
12+
// { dg-error "failed to type resolve root segment" "" { target *-*-* } .-1 }
13+
m1::NodePosition::foo2 => {}
14+
// { dg-error "failed to type resolve root segment" "" { target *-*-* } .-1 }
15+
}
16+
}
17+
18+
pub fn main() {}

0 commit comments

Comments
 (0)