leanprover / leanprover/lean4

`Decidable` synthesis failure when `if`-conditioning on a tactic-containing `match`

Open
#9,212 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

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

Description

An if expression that cases on a local binding of a Bool-valued result of matching on x[n] notation leads to a Decidable synthesis failure.

Context

This issue arose when trying to condition on a local let-binding that used the matches syntax sugar—something of the form

...
let cond := stx[1].getHeadInfo matches .synthetic
let val := if cond then ...
...
Steps to Reproduce

Refer to the following code:

def f [GetElem α Nat Bool P] (x : α) (h : P x 0) : String :=
  let cond :=
    match x[0] with
    | true => false
    | false => true
  if cond then "foo" else "bar" -- typeclass instance problem is stuck, it is often due to metavariables\n Decidable ?m.210

Expected behavior: The declaration elaborates successfully.

Actual behavior: The indicated type-class synthesis failure occurs.

Versions
  • Lean 4.23.0-nightly-2025-07-05
  • Lean 4.21.0
Additional Information

Note that the error disappears if (a) one inlines the match (e.g., if x[0] matches true ...) or (b) one writes getElem x 0 h directly, eliminating the get_elem_tactic-containing macro expansion. More generally, other (but not all) tactic invocations in the match discriminant also induce similar errors, such as this one:

#check
  let cond := match not (by exact false) with | true => false | false => true
  if cond then "foo" else "bar"  -- Application type mismatch: ... cond has type Bool but is expected to have type Prop

(But delete the not and it elaborates successfully.)

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 provided GetElem example on Lean 4.23.0-nightly-2025-07-05, then compare it with the inline-match and direct getElem variants. Trace elaboration around the tactic-containing match discriminant and local let; done means the declaration elaborates successfully without the Decidable synthesis failure.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.