leanprover / leanprover/lean4

A match expression as example return type triggers lean.unknownIdentifier error

Open
#12,985 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

This should be accepted:

example (x : Bool) :
    match x with
    | true  => String
    | false => Nat
  :=
  match x with
  | true => "hello"
  | false => (42: Nat)

It currently fails with

Unknown constant `_example.match_1`
Error code: lean.unknownIdentifier
Context

It is accepted if I turn example into def foo.

It is also accepted if I use a let to name the return type:

example (x : Bool) :
    let τ := match x with
      | true  => String
      | false => Nat
    τ
  :=
  match x with
  | true => "hello"
  | false => (42: Nat)
Steps to Reproduce
  1. Write any example having as its return type a match expression.

Expected behavior: No errors.

Actual behavior: An error is triggered. Apparently the match is compiled as an internal identifier which is however not in scope where it should be.

Versions

Lean 4.30.0-nightly-2026-03-19
Target: x86_64-unknown-linux-gnu

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal example in Lean nightly and compare it with the working def foo and let variants. Trace how the example's match return type is handled, then verify that the original example is accepted without a lean.unknownIdentifier error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.