This PR improves the “expected type mismatch” error message by omitting the type's types when they are defeq, and putting them into separate lines when not. I found it rather tediuos to parse the error message when the expected type is long, because I had to find the `:` in the middle of a large expression somewhere. Also, when both are of sort `Prop` or `Type` it doesn't add much value to print the sort (and it’s only one hover away anyways).
60 lines
1.2 KiB
Text
60 lines
1.2 KiB
Text
import Lean
|
||
|
||
/-- info: And.intro {a b : Prop} (left : a) (right : b) : a ∧ b -/
|
||
#guard_msgs in
|
||
#check And.intro
|
||
|
||
/--
|
||
info: @Or.rec : ∀ {a b : Prop} {motive : a ∨ b → Prop},
|
||
(∀ (h : a), motive ⋯) → (∀ (h : b), motive ⋯) → ∀ (t : a ∨ b), motive t
|
||
-/
|
||
#guard_msgs in
|
||
#check @Or.rec
|
||
|
||
/-- info: Eq.{u_1} {α : Sort u_1} : α → α → Prop -/
|
||
#guard_msgs in
|
||
#check Eq
|
||
|
||
/--
|
||
info: @Eq.rec : {α : Sort u_2} →
|
||
{a : α} → {motive : (a_1 : α) → a = a_1 → Sort u_1} → motive a ⋯ → {a_1 : α} → (t : a = a_1) → motive a_1 t
|
||
-/
|
||
#guard_msgs in
|
||
#check @Eq.rec
|
||
|
||
/-!
|
||
The `#check` command also typechecks the result to help users debug buggy elaborators.
|
||
-/
|
||
section
|
||
open Lean
|
||
|
||
def expr_1eq1 : Expr := mkApp3 (.const ``Eq [0]) (.const ``Nat []) (mkNatLit 1) (mkNatLit 1)
|
||
|
||
elab "elab_1eq1" : term => return expr_1eq1
|
||
|
||
/--
|
||
error: Application type mismatch: In the application
|
||
@Eq Nat
|
||
the argument
|
||
Nat
|
||
has type
|
||
Type
|
||
of sort `Type 1` but is expected to have type
|
||
Prop
|
||
of sort `Type`
|
||
-/
|
||
#guard_msgs in #check elab_1eq1
|
||
|
||
/--
|
||
error: Application type mismatch: In the application
|
||
@Eq Nat
|
||
the argument
|
||
Nat
|
||
has type
|
||
Type
|
||
of sort `Type 1` but is expected to have type
|
||
Prop
|
||
of sort `Type`
|
||
-/
|
||
#guard_msgs in #reduce elab_1eq1
|
||
end
|