lean4-htt/tests/lean/run/issue5562.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

66 lines
1.2 KiB
Text

import Lean
/-!
This test checks that we can enter, typecheck etc. terms that are only type-correct at
transparency `all`.
-/
open Lean Meta
def T := Nat → Nat
def x : T := fun n => n + 1
-- All well:
def n1 : Nat := x 1
-- Now we make `T` irreducible. A bunch of things should break:
attribute [irreducible] T
/--
error: Function expected at
x
but this term has type
T
Note: Expected a function because this term is being applied to the argument
1
-/
#guard_msgs in
def n2 : Nat := x 1
-- NB: Checking does not break! Always done at transparency `all`.
run_meta do
Meta.check (.app (mkConst ``x) (mkNatLit 1))
-- Type inference fails:
/--
error: function expected
x 1
-/
#guard_msgs in
run_meta do
let _ ← Meta.inferType (.app (mkConst ``x) (mkNatLit 1))
-- But succeeds at transparency .all
run_meta do
withTransparency .all do
let _ ← Meta.inferType (.app (mkConst ``x) (mkNatLit 1))
-- An elaborator that sets transparency to .all:
elab "with_unfolding_all" t:term : term <= expectedType? =>
withTransparency .all <|
Elab.Term.elabTerm t expectedType?
/--
error: function expected
x 1
-/
#guard_msgs in
def n3 : Nat := with_unfolding_all x 1