diff --git a/src/Lean/PrettyPrinter/Delaborator/Builtins.lean b/src/Lean/PrettyPrinter/Delaborator/Builtins.lean index 187b283027..e97b47ddc5 100644 --- a/src/Lean/PrettyPrinter/Delaborator/Builtins.lean +++ b/src/Lean/PrettyPrinter/Delaborator/Builtins.lean @@ -550,9 +550,29 @@ def delabLam : Delab := | `(fun $binderGroups* => $stxBody) => `(fun $group $binderGroups* => $stxBody) | _ => `(fun $group => $stxBody) +/-- +Similar to `delabBinders`, but tracking whether `forallE` is dependent or not. + +See issue #1571 +-/ +private partial def delabForallBinders (delabGroup : Array Syntax → Bool → Syntax → Delab) (curNames : Array Syntax := #[]) (curDep := false) : Delab := do + let dep := !(← getExpr).isArrow + if !curNames.isEmpty && dep != curDep then + -- don't group + delabGroup curNames curDep (← delab) + else + let curDep := dep + if ← shouldGroupWithNext then + -- group with nested binder => recurse immediately + withBindingBodyUnusedName fun stxN => delabForallBinders delabGroup (curNames.push stxN) curDep + else + -- don't group => delab body and prepend current binder group + let (stx, stxN) ← withBindingBodyUnusedName fun stxN => return (← delab, stxN) + delabGroup (curNames.push stxN) curDep stx + @[builtinDelab forallE] -def delabForall : Delab := - delabBinders fun curNames stxBody => do +def delabForall : Delab := do + delabForallBinders fun curNames dependent stxBody => do let e ← getExpr let prop ← try isProp e catch _ => pure false let stxT ← withBindingDomain delab @@ -562,9 +582,6 @@ def delabForall : Delab := -- here `curNames.size == 1` | BinderInfo.instImplicit => `(bracketedBinderF|[$curNames.back : $stxT]) | _ => - -- heuristic: use non-dependent arrows only if possible for whole group to avoid - -- noisy mix like `(α : Type) → Type → (γ : Type) → ...`. - let dependent := curNames.any fun n => hasIdent n.getId stxBody -- NOTE: non-dependent arrows are available only for the default binder info if dependent then if prop && !(← getPPOption getPPPiBinderTypes) then diff --git a/tests/lean/1571.lean b/tests/lean/1571.lean new file mode 100644 index 0000000000..b4c60b644b --- /dev/null +++ b/tests/lean/1571.lean @@ -0,0 +1,5 @@ +#check True → (∃ a : Nat, a = a) +-- True → ∃ a, a = a : Prop + +#check True → (∃ b : Nat, b = b) +-- True → ∃ b, b = b : Prop diff --git a/tests/lean/1571.lean.expected.out b/tests/lean/1571.lean.expected.out new file mode 100644 index 0000000000..3fbe7370d9 --- /dev/null +++ b/tests/lean/1571.lean.expected.out @@ -0,0 +1,2 @@ +True → ∃ a, a = a : Prop +True → ∃ b, b = b : Prop diff --git a/tests/lean/815b.lean.expected.out b/tests/lean/815b.lean.expected.out index 734c3220da..ebd49e986b 100644 --- a/tests/lean/815b.lean.expected.out +++ b/tests/lean/815b.lean.expected.out @@ -141,7 +141,7 @@ IsSmooth fun g => g Transformer fun redf a => redf - [Meta.synthInstance.resume] propagating ∀ (a : α), + [Meta.synthInstance.resume] propagating α → IsSmooth fun a => a to subgoal α → IsSmooth fun g => g of ∀ (a : α), IsSmooth fun g => g a [Meta.synthInstance.resume] size: 2 [Meta.synthInstance.resume] propagating ∀ (a : α), @@ -155,10 +155,10 @@ IsSmooth fun g => g Transformer fun redf a => redf - [Meta.synthInstance.resume] propagating ∀ (a : α), + [Meta.synthInstance.resume] propagating α → IsSmooth fun b a => b a to subgoal α → IsSmooth fun g => g of ∀ (a : α), IsSmooth fun g => g a [Meta.synthInstance.resume] size: 8 - [Meta.synthInstance.resume] propagating ∀ (a : α), + [Meta.synthInstance.resume] propagating α → IsSmooth fun a => a to subgoal α → IsSmooth fun g => g of ∀ (a : α), IsSmooth fun g => g a [Meta.synthInstance.resume] size: 5 [Meta.synthInstance.resume] propagating ∀ (a : α), diff --git a/tests/lean/PPRoundtrip.lean.expected.out b/tests/lean/PPRoundtrip.lean.expected.out index e36345ca45..42757ecf40 100644 --- a/tests/lean/PPRoundtrip.lean.expected.out +++ b/tests/lean/PPRoundtrip.lean.expected.out @@ -30,7 +30,8 @@ fun {α} a => @toString α inst a (α : Type) → α -(α β : Type) → α +(α : Type) → + Type → α Type → Type → Type (α : Type) → α → α {α : Type} → α diff --git a/tests/lean/autoIssue.lean.expected.out b/tests/lean/autoIssue.lean.expected.out index fba698d1cc..cec0f07287 100644 --- a/tests/lean/autoIssue.lean.expected.out +++ b/tests/lean/autoIssue.lean.expected.out @@ -5,7 +5,7 @@ this : z.x = 1 z : A this : z.x = 1 ⊢ z.x = 1 -@A.rec : {motive : A → Sort u_1} → ((x : Nat) → x = 1 → motive (A.mk x)) → (t : A) → motive t +@A.rec : {motive : A → Sort u_1} → ((x : Nat) → (a' : x = 1) → motive (A.mk x)) → (t : A) → motive t z : A x : Nat a' : x = 1 diff --git a/tests/lean/congrThm.lean.expected.out b/tests/lean/congrThm.lean.expected.out index ccdfe94b5a..13b03fd81d 100644 --- a/tests/lean/congrThm.lean.expected.out +++ b/tests/lean/congrThm.lean.expected.out @@ -1,8 +1,8 @@ ∀ (p p_1 : Prop), p = p_1 → - ∀ {inst : Decidable p} {inst_1 : Decidable p_1} (a a_1 : Nat), - a = a_1 → ∀ (h : a > 0), g p a h = g p_1 a_1 (_ : a_1 > 0) + ∀ {inst : Decidable p} {inst_1 : Decidable p_1} (a a_1 : Nat) (e_3 : a = a_1) (h : a > 0), + g p a h = g p_1 a_1 (_ : a_1 > 0) ∀ (p p_1 : Prop), p = p_1 → - ∀ {inst : Decidable p} [inst_1 : Decidable p_1] (a a_1 : Nat), - a = a_1 → ∀ (h : a > 0), g p a h = g p_1 a_1 (_ : a_1 > 0) + ∀ {inst : Decidable p} [inst_1 : Decidable p_1] (a a_1 : Nat) (e_3 : a = a_1) (h : a > 0), + g p a h = g p_1 a_1 (_ : a_1 > 0) diff --git a/tests/lean/congrThmIssue.lean.expected.out b/tests/lean/congrThmIssue.lean.expected.out index 0b54d05197..ba327af1bc 100644 --- a/tests/lean/congrThmIssue.lean.expected.out +++ b/tests/lean/congrThmIssue.lean.expected.out @@ -4,7 +4,7 @@ cap : Nat backing : Fin cap → Option α size : Nat h_size : size ≤ cap -h_full : ∀ (i : Nat), i < size → Option.isSome (backing { val := i, isLt := (_ : i < cap) }) = true +h_full : ∀ (i : Nat) (h : i < size), Option.isSome (backing { val := i, isLt := (_ : i < cap) }) = true i : Nat h : i < size ⊢ Option.isSome diff --git a/tests/lean/ppMotives.lean.expected.out b/tests/lean/ppMotives.lean.expected.out index d4d78f944d..f99a4985ae 100644 --- a/tests/lean/ppMotives.lean.expected.out +++ b/tests/lean/ppMotives.lean.expected.out @@ -11,7 +11,7 @@ protected def Nat.add : Nat → Nat → Nat := fun x x_1 => Nat.brecOn (motive := fun x => Nat → Nat) x_1 (fun x f x_2 => - (match (motive := (x x : Nat) → Nat.below (motive := fun x => Nat → Nat) x → Nat) x_2, x with + (match (motive := Nat → (x : Nat) → Nat.below (motive := fun x => Nat → Nat) x → Nat) x_2, x with | a, Nat.zero => fun x => a | a, Nat.succ b => fun x => Nat.succ (PProd.fst x.fst a)) f) diff --git a/tests/lean/precissues.lean.expected.out b/tests/lean/precissues.lean.expected.out index 9acf412e00..24a48746ba 100644 --- a/tests/lean/precissues.lean.expected.out +++ b/tests/lean/precissues.lean.expected.out @@ -25,6 +25,6 @@ p ∧ ¬q : Prop ¬p = q : Prop ¬p = q : Prop id ¬p : Prop -∀ (a a : Nat), a = a : Prop +Nat → ∀ (a : Nat), a = a : Prop id : ?m → ?m precissues.lean:41:10: error: expected command