diff options
author | Liam Naddell <liam.naddell@mail.utoronto.ca> | 2024-07-12 20:56:08 -0400 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-07-18 12:43:05 +0000 |
commit | bfee9e02cdc267311a23b352d5028e619fdabaa0 (patch) | |
tree | 5e0f7625e1304254615252860b09e2d30dc017ab /gcc | |
parent | 043ce276e5eb421c087d329dab4cc790e2a0a060 (diff) | |
download | gcc-bfee9e02cdc267311a23b352d5028e619fdabaa0.zip gcc-bfee9e02cdc267311a23b352d5028e619fdabaa0.tar.gz gcc-bfee9e02cdc267311a23b352d5028e619fdabaa0.tar.bz2 |
[#3046] ICE on failing to find enum variant
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc:
Fix ICE caused by not finding enum variant by adding new error
message
gcc/testsuite/ChangeLog:
* rust/compile/issue-3046.rs:
Add test for new error message
Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.cc | 9 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3046.rs | 23 |
2 files changed, 31 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index d4517f3..b2bb717 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -194,7 +194,14 @@ TypeCheckExpr::visit (HIR::CallExpr &expr) HirId variant_id; bool ok = context->lookup_variant_definition ( expr.get_fnexpr ()->get_mappings ().get_hirid (), &variant_id); - rust_assert (ok); + + if (!ok) + { + rust_error_at (expr.get_locus (), ErrorCode::E0423, + "expected function, tuple struct or tuple " + "variant, found enum"); + return; + } TyTy::VariantDef *lookup_variant = nullptr; ok = adt->lookup_variant_by_id (variant_id, &lookup_variant); diff --git a/gcc/testsuite/rust/compile/issue-3046.rs b/gcc/testsuite/rust/compile/issue-3046.rs new file mode 100644 index 0000000..c982cc9 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3046.rs @@ -0,0 +1,23 @@ +enum Res { + OK, + BAD, +} + +enum LOption { + Some(i32), + None, +} + +fn test(v: LOption) -> Res { + return Res::BAD; +} + + +fn main() { + // Should be: + // test(LOption::Some(2)); + // + test(LOption(2)); + // { dg-error "expected function, tuple struct or tuple variant, found enum" "" { target *-*-* } .-1 } + // { dg-error "failed to resolve type for argument expr in CallExpr" "" { target *-*-* } .-2 } +} |