leanprover / leanprover/lean4

Type error for syntax `match` appears within pattern itself

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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.