Skip to content

Unclear error when mixing literals and constructors in match alternatives #11186

@MixedMatched

Description

@MixedMatched

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

When doing a match with alternatives of both literal values and constructors of those literal value types, an unknown free variable error appears.

Context

Discussion on Zulip

Steps to Reproduce

A few examples that reproduce the error on Lean nightly on the Lean playground:

def stringMatch : Option Nat :=
  match "Bad" with
  | String.ofByteArray _ _ => some 1
  | "Eek" => some 2
  | _ => none -- unknown free variable `_fvar.149`

def charMatch :=
  match 'X' with
  | Char.mk 5 _ => some 1
  | 'A' => some 2
  | _ => none -- unknown free variable `_fvar.836`

def uInt8Match :=
  match (5: UInt8) with
  | UInt8.ofBitVec (BitVec.ofFin 3) => some 1
  | 5 => some 2
  | _ => none -- unknown free variable `_fvar.1026`

Expected behavior: The match statement either works with both kinds of pattern, or gives a clear error describing what the problem is and what the developer should do.

Actual behavior: The match statement gives an unclear and unactionable error.

Versions

Lean 4.26.0-nightly-2025-11-14
Target: x86_64-unknown-linux-gnu
live.lean-lang.org

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions