leanprover / leanprover/lean4

pp.all cannot round-trip applied lambdas with implicit binders

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

Even pp.all true seems to not be enough to print terms of the form Expr.app `(fun {x} => y) z.

Context

Zulip thread

Steps to Reproduce

Run

import Lean

open Lean

elab "thats_illegal" : term =>
  return Expr.app
    (Expr.lam `n (.const `Nat []) (.bvar 0) .implicit)
    (Expr.const `Nat.zero [])

set_option pp.all true

/-- info: (@fun {n : Nat} => n) Nat.zero : Nat -/
#guard_msgs in #check thats_illegal

-- copied from the output, but doesn't work!
#check ((@fun {n : Nat} => n) Nat.zero : Nat)

-- fixed by hand, but not the same expression any more
#check (@id _ (fun {n : Nat} => n) Nat.zero : Nat)

Expected behavior: The output of #check with pp.all true should round-trip

Actual behavior: The resulting expression has a type error

Versions

4.14.0-rc2

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

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 using pp.all true, Expr.app, and the #check commands. Compare the printed applied lambda with the hand-fixed expression and trace how pretty-printed implicit binders are parsed. Done means the #check output round-trips without a type error while preserving the intended expression.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.