Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using wrong enum variant results in ice #3140

Open
liamnaddell opened this issue Aug 23, 2024 · 1 comment
Open

Using wrong enum variant results in ice #3140

liamnaddell opened this issue Aug 23, 2024 · 1 comment
Labels

Comments

@liamnaddell
Copy link
Contributor

Code

enum State {
    Succeeded,
    Failed,
}

fn print_on_failure(state: &State) {
    let mut num = 0;
    match *state {
        // error: expected unit struct, unit variant or constant, found tuple
        //        variant `State::Failed`
        State::Failed => {
            num = 1;
        },
        State::Succeeded => {
            num = 2;
        },
        _ => ()
    }
}

fn main() {
    let b = State::Failed(1);

    print_on_failure(&b);

}

Meta

  • What version of Rust GCC were you using, git sha if possible.

Error output

some_strange_type_check_bug.rs:22:13: error: expected function, tuple struct or tuple variant, found struct ‘State’ [E0423]
   22 |     let b = State::Failed(1);
      |             ^~~~~
some_strange_type_check_bug.rs:24:23: error: cannot find value ‘b’ in this scope [E0425]
   24 |     print_on_failure(&b);
      |                       ^
Backtrace

crab1: internal compiler error: in TyVar, at rust/typecheck/rust-tyty-util.cc:31
0x131f9ff Rust::TyTy::TyVar::TyVar(unsigned int)
  ../../gccrs/gcc/rust/typecheck/rust-tyty-util.cc:31
0x138500b Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BorrowExpr&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc:1400
0x11cdd87 Rust::HIR::BorrowExpr::accept_vis(Rust::HIR::HIRExpressionVisitor&)
  ../../gccrs/gcc/rust/hir/tree/rust-hir.cc:3809
0x137f7af Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc:42
0x13205d3 Rust::TyTy::TypeCheckCallExpr::visit(Rust::TyTy::FnType&)
  ../../gccrs/gcc/rust/typecheck/rust-tyty-call.cc:143
0x1306db7 Rust::TyTy::FnType::accept_vis(Rust::TyTy::TyVisitor&)
  ../../gccrs/gcc/rust/typecheck/rust-tyty.cc:1879
0x1387dff Rust::TyTy::TypeCheckCallExpr::go(Rust::TyTy::BaseType*, Rust::HIR::CallExpr&, Rust::TyTy::VariantDef&, Rust::Resolver::TypeCheckContext*)
  ../../gccrs/gcc/rust/typecheck/rust-tyty-call.h:39
0x138037b Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::CallExpr&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc:239
0x11d0867 Rust::HIR::CallExpr::accept_vis(Rust::HIR::HIRExpressionVisitor&)
  ../../gccrs/gcc/rust/hir/tree/rust-hir.cc:4865
0x137f7af Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc:42
0x138a77f Rust::Resolver::TypeCheckStmt::visit(Rust::HIR::ExprStmt&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-stmt.cc:41
0x11d066f Rust::HIR::ExprStmt::accept_vis(Rust::HIR::HIRStmtVisitor&)
  ../../gccrs/gcc/rust/hir/tree/rust-hir.cc:4811
0x138a71b Rust::Resolver::TypeCheckStmt::Resolve(Rust::HIR::Stmt*)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-stmt.cc:34
0x1381d53 Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::BlockExpr&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc:593
0x11d0e5f Rust::HIR::BlockExpr::accept_vis(Rust::HIR::HIRExpressionVisitor&)
  ../../gccrs/gcc/rust/hir/tree/rust-hir.cc:5027
0x137f7af Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-expr.cc:42
0x1366f0b Rust::Resolver::TypeCheckItem::visit(Rust::HIR::Function&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-item.cc:587
0x11d0ed7 Rust::HIR::Function::accept_vis(Rust::HIR::HIRVisItemVisitor&)
  ../../gccrs/gcc/rust/hir/tree/rust-hir.cc:5039
0x13646bb Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check-item.cc:55
0x12ea887 Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
  ../../gccrs/gcc/rust/typecheck/rust-hir-type-check.cc:70
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

@philberty
Copy link
Member

Interesting this is probably going to start to be more of an issue. I decided back ages ago with that TyVar that it should assert if no type was found but it probably needs to start doing the proper thing of returning an error type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants