`Decidable` synthesis failure when `if`-conditioning on a tactic-containing `match`
Nobody has claimed this yet.
- 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:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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