leanprover / leanprover/lean4

Syntax pattern $foo:with_type fails unhelpfully

Open
#2,957 0 comments 0 reactions 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

This papercut in error reporting has been causing me mild frustration and prevented me from figuring out syntax by trying, maybe it can be improved:

import Lean

def bar := leading_parser "a_bar"
def foo := leading_parser bar

namespace Works
def test (stx : Lean.Syntax) : Bool := 
  match stx with
  | `(foo| $bar:bar) => true
  | _ => false
end Works

namespace FailsUnhelpfully
def test (stx : Lean.Syntax) : Bool := 
  match stx with
  | `(foo| $bar:barr) => true
  | _ => false

end FailsUnhelpfully

If I want to use a “parser annotation”(?) in a syntax pattern, but mistype the parser (or don’t have it in scope), I get

unexpected token '$'; expected 'a_bar', 'bar' or 'foo'

What I’d like to see is something telling me that barr isn't in scope.

My guess is that somewhere this name lookup fails, but the parser’s backtracking backtracks that error, when instead it (maybe?) should be a non-backtrackable error?

Versions

4.3.0-rc2

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

Begin by running the supplied Lean.Syntax pattern reproducer, comparing the working bar annotation with the misspelled barr case. Trace parser-annotation name lookup and error backtracking; done means an out-of-scope or unknown parser name produces a direct diagnostic instead of the generic unexpected-token message.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.