Skip to content

Commit

Permalink
fix: make sure #check id heeds pp.raw (leanprover#6181)
Browse files Browse the repository at this point in the history
This PR fixes a bug where the signature pretty printer would ignore the
current setting of `pp.raw`. This fixes an issue where `#check ident`
would not heed `pp.raw`. Closes leanprover#6090.
  • Loading branch information
kmill authored Nov 23, 2024
1 parent 4a69643 commit ba3f2b3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/Lean/PrettyPrinter.lean
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ open Delaborator in
/-- Pretty-prints a declaration `c` as `c.{<levels>} <params> : <type>`. -/
def ppSignature (c : Name) : MetaM FormatWithInfos := do
let decl ← getConstInfo c
let e := .const c (decl.levelParams.map mkLevelParam)
let (stx, infos) ← delabCore e (delab := delabConstWithSignature)
return ⟨← ppTerm ⟨stx⟩, infos⟩ -- HACK: not a term
let e := Expr.const c (decl.levelParams.map mkLevelParam)
if pp.raw.get (← getOptions) then
return s!"{e} : {decl.type}"
else
let (stx, infos) ← delabCore e (delab := delabConstWithSignature)
return ⟨← ppTerm ⟨stx⟩, infos⟩ -- HACK: not a term

private partial def noContext : MessageData → MessageData
| MessageData.withContext _ msg => noContext msg
Expand Down
2 changes: 1 addition & 1 deletion tests/lean/root.lean.expected.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ root.lean:35:14-35:22: error: protected declarations must be in a namespace
root.lean:41:7-41:8: error: unknown identifier 'h'
root.lean:43:7-43:8: error: unknown identifier 'f'
Bla.f (x : Nat) : Nat
prv (x : Nat) : Nat
_private.root.0.prv : Nat -> Nat
root.lean:90:89-90:93: error: unsolved goals
x : Nat
⊢ isEven (x + 1 + 1) = isEven x
Expand Down
30 changes: 30 additions & 0 deletions tests/lean/run/6090.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/-!
# Make sure `#check` heeds `pp.raw`
https://github.com/leanprover/lean4/issues/6090
-/

section
/-- info: id.{u} {α : Sort u} (a : α) : α -/
#guard_msgs in #check id
/-- info: @id : {α : Sort u_1} → α → α -/
#guard_msgs in #check @id
-- '#print' was unaffected, but throw in a test anyway.
/--
info: def id.{u} : {α : Sort u} → α → α :=
fun {α} a => a
-/
#guard_msgs in #print id

set_option pp.raw true

/-- info: id.{u} : forall {α : Sort.{u}}, α -> α -/
#guard_msgs in #check id
/-- info: id.{u_1} : forall {α : Sort.{u_1}}, α -> α -/
#guard_msgs in #check @id
-- '#print' was unaffected, but throw in a test anyway.
/--
info: def id.{u} : forall {α : Sort.{u}}, α -> α :=
fun {α : Sort.{u}} (a : α) => a
-/
#guard_msgs in #print id
end

0 comments on commit ba3f2b3

Please sign in to comment.