leanprover / leanprover/lean4

`do` lifting is not handled correctly in antiquotations

Open
#3,827 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug do-notation P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
  • Put an X between the brackets on this line if you have done all of the following:
    • Check that your issue is not already filed.
    • Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.
Description

When building Syntax or Qq quotations involving a do $(← getArg) antiquotation, the parser rejects the even if there is a suitable enclosing do block. This is unexpected; the lifting behavior of antiquotations should be unaffected by the syntax that they are interpolated within.

Context

This issue also arises with if $(← getCond) then _ else _ quotations after #3820.

Steps to Reproduce
  1. Run the following
import Lean
open Lean

def foo : MetaM (TSyntax ``Parser.Term.doSeq) := do `(Parser.Term.doSeq| pure 37)

#check do `(do $(← foo))

#check do
  let mkDo x := `(do $x)
  mkDo (← foo)

Expected behavior: Both #checks succeed

Actual behavior: The first one fails, with the error

invalid use of (<- ...), must be nested inside a 'do' expression

Versions

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

Start with the minimal Lean reproduction in the issue and inspect how Syntax or Qq quotations process antiquotations containing inside do expressions. Run both #check examples to confirm the current failure. Done means both checks succeed, including the mkDo example and the related quotation behavior described after #3820.

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.