lean4-htt/tests/lean/run/invalid_field_notation_mvar.lean
jrr6 7ed716f904
feat: improve projection and field-notation errors (#8986)
This PR improves the error messages produced by invalid projections and
field notation. It also adds a hint to the "function expected" error
message noting the argument to which the term is being applied, which
can be helpful for debugging spurious "function expected" messages
actually caused by syntax errors.

---------

Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>
2025-06-26 18:36:47 +00:00

53 lines
1.2 KiB
Text

structure Foo where (n : Nat)
def Foo.f1 (f : Foo) : Nat := f.n
def Foo.f2 (f : Foo) : Nat := f.n
def Foo.f3 (f : Foo) : Nat := f.n
def Foo.f4 (f : Foo) : Nat := f.n
def Foo.f5 (f : Foo) : Nat := f.n
/--
error: Invalid field notation: Type of
f
is not known; cannot resolve field `n`
---
error: Invalid field notation: Type of
g
is not known; cannot resolve field `n`
---
error: Invalid field notation: Type of
f
is not known; cannot resolve field `f1`
---
error: Invalid field notation: Type of
g
is not known; cannot resolve field `f2`
---
error: Invalid field notation: Type of
h
is not known; cannot resolve field `f3`
---
error: Invalid field notation: Type of
f
is not known; cannot resolve field `f4`
---
error: Invalid field notation: Type of
g
is not known; cannot resolve field `f5`
---
error: Invalid field notation: Type of
h
is not known; cannot resolve field `f6`
-/
#guard_msgs in
example := (λ f g h =>
let x : Foo := ⟨f.n + 1⟩;
let y : Foo := ⟨g.n + 1⟩;
(λ f g h => f.f1 + g.f2 + h.f3 + f.f4 + g.f5 + h.f6) f g h)
/--
error: Invalid field notation: Type of
id x
is not known; cannot resolve field `foo`
-/
#guard_msgs in
example := fun x => (id x).foo