Skip to content

ICE in HLIR match compilation: match exhaustion failure for wrong-arity enum pattern in or-pattern with literal #25826

@jubnzv

Description

@jubnzv

The compiler emits bug[ICE12003]: INTERNAL COMPILER ERROR — "Generated a failure expression, which should not be allowed under match exhaustion" — when compiling a match expression that has a wrong-arity enum pattern combined with a literal pattern in an or-pattern.

The issue is that the typing pass correctly reports E04016: too few arguments for the wrong-arity pattern but does not abort compilation.

MRE:

module 0x42::m {
    public enum E has drop {
        A(u64),
        C(u64, u64, u64),
    }

    fun t(): u64 {
        let subject = E::A(0);
        match (subject) {
            E::A(x) if (x == &0) => x,
            E::A(x) | E::C(x, _, 0) | E::C(_, x) => x,
        }
    }
}

Reproduce steps:

cd external-crates/move
cargo +nightly run --release -p move-compiler --bin move-check -- mre.move

Output:

bug[ICE12003]: INTERNAL COMPILER ERROR
   ┌─ mre.move:9:25
   │
 9 │           match (subject) {
   │ ╭─────────────────────────^
10 │ │             E::A(x) if (x == &0) => x,
11 │ │             E::A(x) | E::C(x, _, 0) | E::C(_, x) => x,
12 │ │         }
   │ ╰─────────^ Generated a failure expression, which should not be allowed under match exhaustion.
   │
   = The Move compiler has encountered an internal compiler error.
      Please report this issue to the Mysten Labs Move language team,
      including this error and any relevant code, to the Mysten Labs issue tracker
      at : https://github.com/MystenLabs/sui/issues

error[E04016]: too few arguments
   ┌─ mre.move:11:39
   │
11 │             E::A(x) | E::C(x, _, 0) | E::C(_, x) => x,
   │                                       ^^^^^^^^^^ Missing pattern for field '2' in '0x42::m::E::C'

Expected behavior: clean error message about wrong pattern arity without ICE.

Git commit: fc75182
Build: release
cargo 1.91.0-nightly (840b83a10 2025-07-30)
rustc 1.91.0-nightly (3672a55b7 2025-08-13)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions