leanprover / leanprover/lean4

Typeclass inference fails if argument is a `match`

Open
#12,381 5 comments 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

Typeclass inference fails unexpectedly if an argument is a match.

Context

No relevant context.

Steps to Reproduce

Consider the following input:

class Test (n : Nat)

instance {n} : Test n := ⟨⟩

-- works
#synth Test 1
-- fails
#synth Test (match ?_ with | 0 => 1 | _ => 1)
-- works
#synth Test (if ?_ == 0 then 1 else 1)

(This repro was originally posted by lzy0505 here.)

Expected behavior: Inference succeeds.

Actual behavior: Inference fails.

Versions

Lean 4.29.0-nightly-2026-02-08
Target: x86_64-unknown-linux-gnu

Additional Information

None.

Impact

Both lzy0505 and myself bumped into this while using iris-lean. The bug means that Iris theorems of the form P \vdash Q where P is a match are not easy to use in iris-lean.

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 with the minimal #synth reproduction in the issue and trace how typeclass inference handles the match expression, comparing it with the working if expression. Confirm the change against the shown Test instance and verify that inference succeeds for Test (match ?_ with | 0 => 1 | _ => 1) without Mathlib or Batteries.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.