leanprover / leanprover/lean4

Overlapping tactic syntax hides error messages

Open
#12,394 0 comments 1 reaction 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

Certain tactics, including at least apply and exact, hide error messages when there is another elaborator for the same syntax.

For example, Mathlib defines an applyWith tactic using optConfig. Since optConfig allows the configuration to be absent, apply t can be both parsed as built-in apply and Mathlib's applyWith. When there is such overlapping syntax, and an error happens (this error would occur in the built-in apply and in Mathlib's applyWith), this error is silently ignored and a sorry is inserted.

module

public meta import Lean.Elab.Eval
public meta import Lean.Elab.Tactic.ElabTerm

public meta section

open Lean Parser Meta Elab Tactic Term

elab "apply" t:term : tactic => do
  evalApplyLikeTactic (fun g e => g.apply e (term? := some m!"`{e}`")) t

def MyProp (n : Nat) : Prop := n = n

theorem MyProp.mk (n : Nat) : MyProp n := by rw [MyProp]

-- this emits a warning that sorry was used, but no errors
theorem foo : MyProp 1337 := by
  apply MyProp.mk "foo"
  exact "qed"
Context

Found in Mathlib for applyWith, which now has a workaround consisting of a custom parser that can't be ambiguous with builtin apply. Discussed on Zulip here: https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/optConfig.20causes.20tactics.20to.20be.20ignored

Steps to Reproduce
  1. Declare new syntax for apply that overlaps with existing apply syntax.
  2. Write an erroring use of apply, for example try to close the goal with a term of the wrong type.
  3. Receive no visible error.

Expected behavior: One error message is displayed, for example a type mismatch.

Actual behavior: No error message is displayed, the goal is closed with a sorry.

Versions

v4.28.0-rc1, nightly Lean 4.29.0-nightly-2026-02-09

Additional Information

n/a

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

Run the minimal reproduction with the imports Lean.Elab.Eval and Lean.Elab.Tactic.ElabTerm, then inspect how overlapping apply syntax and optConfig elaborators handle errors. Compare the built-in apply path with the overlapping elaborator. Done means the type-mismatch error is displayed and no sorry is inserted.

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.