Type error for syntax `match` appears within pattern itself
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
A syntax quotation match doesn't appear to be setting the types of the pattern variables in a strong enough way to prevent type errors from propagating into the matching code.
Context
#lean4 > weird type mismatch error location @ 💬
Steps to Reproduce
Consider
import Lean
open Lean Elab Meta Command Tactic
syntax foo := (ppSpace "(" ident " foo " tactic ")" )*
structure Foo where
set_option trace.Elab.match_syntax true
def elabFoo : Syntax → CommandElabM Unit
| `(foo| $[($ids foo $tac)]*) => do
let mut userArgs : NameMap (TSyntax `term) := {}
for (name, t) in (ids.map (·.getId)).zip tac do
userArgs := userArgs.insert name t
| _ => throwUnsupportedSyntax
There is a type error since according to the pattern, tac : TSyntax `tactic, but according to the Array.zip, we have tac : TSyntax `term.
Expected behavior: The type error appears on the tac argument to zip.
Actual behavior: The type error appears on tac in the syntax quotation.
Versions
Lean 4.19.0-rc2
Target: x86_64-unknown-linux-gnu
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 with the minimal reproducer in the issue, especially the elabFoo syntax quotation and the trace.Elab.match_syntax output. Investigate how the quotation assigns types to pattern variables before Array.zip; done means the diagnostic points to the tac argument of zip rather than the quotation pattern.
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