Skip to content

Commit

Permalink
[#3046] ICE on failing to find enum variant
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
liamnaddell authored and CohenArthur committed Jul 18, 2024
1 parent 043ce27 commit bfee9e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 23 additions & 0 deletions gcc/testsuite/rust/compile/issue-3046.rs
Original file line number Diff line number Diff line change
@@ -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 }
}

0 comments on commit bfee9e0

Please sign in to comment.