leanprover / leanprover/lean4

Ill-typed `match` motive inference

Open
#11,995 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Description

When match generalization is off, abstracting the motive over a discriminant can lead to an ill-typed motive.

Steps to Reproduce
example (x : Nat) (y : Fin (x + 1)) : Fin (y + 2) :=
  match (generalizing := false) x with
  | 0 => 0
  | _ => 0

Expected behavior: No errors

Actual behavior: A type error saying that y has type Fin (x + 1) but is expected to have type Fin (0 + 1)

Versions

Lean 4.28.0-nightly-2026-01-12
Target: x86_64-unknown-linux-gnu

Additional Information

There is similarity to why we do discriminant refinement. I'm not blocked by this, I just noticed while playing around with match elaboration. I think it can be fixed in elabDiscrs by testing whether the type Lean.mkForall userName .default discrType (<- kabstract result.matchType discr) is type-correct. If not, fall back to a constant motive.

Impact

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

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 against the reported Lean nightly version, then inspect the match elaboration path around elabDiscrs. Check how the inferred motive is validated when match generalization is disabled. Done means the example elaborates without a type error and a regression test covers the case.

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
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.