leanprover / leanprover/lean4

Quotation does not detect ambiguity

Open
#6,101 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

Please put an X between the brackets as you perform the following steps:

Description

In the following example, the expr syntax category has two rules, which create an ambiguity: an ident can be directly an expression, or a nullary application. Ideally, this should trigger a warning or an error, but it doesn't, and, although just by looking at the source code, it looks like all the cases of the parse tree are handled, the expression f x reaches the catchall case.

import Lean

open Lean Meta Elab
open Lean.Elab.Command (liftTermElabM)

declare_syntax_cat expr
syntax "#demo " expr : command
syntax:60 ident expr:61* : expr
syntax:90 ident : expr

partial def elab_expr : Lean.TSyntax `expr → CoreM Unit
  | `(expr| $_:ident) => return ()
  | `(expr| $_:ident $args:expr*) => do
    for arg in args do
      elab_expr arg
  | s => throwErrorAt s m!"{repr s}"

elab_rules : command
  | `(command| #demo $expr) => liftTermElabM <| elab_expr expr

#demo f x
Context

See the zulip thread where this issue was first reported.

Versions

Tested on Lean 4.12.0 on a NixOS/nixpkgs unstable computer, and on Lean nightly on live.lean-lang.org.

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 Lean example in the issue and reproduce it against Lean 4.12.0 or the nightly release on live.lean-lang.org. Read the syntax-category rules, parser priority behavior, and the elaboration patterns shown; done means the ambiguity is reported and the demonstrated parse no longer reaches the catchall case.

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.