]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [gccrs#3046] ICE on failing to find enum variant
authorLiam Naddell <liam.naddell@mail.utoronto.ca>
Sat, 13 Jul 2024 00:56:08 +0000 (20:56 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:53 +0000 (16:35 +0100)
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>
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/issue-3046.rs [new file with mode: 0644]

index 6212660e571d63908877fc2ae39b26a3d1ff8a31..0e897813d8f05b14e58caec6609a2871ec87fbb8 100644 (file)
@@ -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 (file)
index 0000000..c982cc9
--- /dev/null
@@ -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 }
+}