lean4-htt/tests/lean/run/invalid_field_notation_function.lean
jrr6 e53f944c83
fix: function field notation errors when head is an fvar (#9595)
This PR improves the error message displayed when writing an invalid
projection on a free variable of function type.
2025-07-28 23:07:02 +00:00

108 lines
2.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-!
# Invalid field notation on expressions of function type
Ensure we produce correct field notation error messages for expressions of function type and not the
fallback "type is not of the form `C ...`" message.
-/
set_option pp.mvars false
def foo : αα := id
/-- error: Unknown constant `foo.bar` -/
#guard_msgs in
example := foo.bar
/--
error: Invalid field `foo`: The environment does not contain `Function.foo`
fun x => x
has type
?_ → ?_
-/
#guard_msgs in
example (f : αα) := (fun x => x).foo
/--
error: Invalid field `foo`: The environment does not contain `Function.foo`
f
has type
αα
-/
#guard_msgs in
example (f : αα) := f.foo
/--
error: Invalid field notation: Type is not of the form `C ...` where C is a constant
f x
has type
α
-/
#guard_msgs in
example (f : αα) (x : α) := (f x).foo
/--
error: Invalid field `foo`: The environment does not contain `Function.foo`
f x
has type
αα
-/
#guard_msgs in
example (f : ααα) (x : α) := (f x).foo
/--
error: Invalid field notation: Type is not of the form `C ...` where C is a constant
foo x
has type
α
-/
#guard_msgs in
example (x : α) := (foo x).foo
def foo.bar := 32
/--
error: Invalid field `bar`: The environment does not contain `Function.bar`
foo
has type
αα
-/
#guard_msgs in
example (foo : αα) := foo.bar
/--
error: Invalid field `foo`: The environment does not contain `Function.foo`
let x := id;
x
has type
?_ → ?_
-/
#guard_msgs in
example := (let x := id; x).foo
/--
error: Invalid field `foo`: The environment does not contain `Function.foo`
?_
has type
αα
-/
#guard_msgs in
example {α} := (by intro h; exact h : αα).foo
/-! Make sure we're not overzealously detecting fvars or implicitly-parameterized values in function position -/
/--
error: Invalid field `foo`: The environment does not contain `Nat.foo`
n
has type
Nat
-/
#guard_msgs in
example (n : Nat) := n.foo
/--
error: Invalid field `foo`: The environment does not contain `List.foo`
[]
has type
List Nat
-/
#guard_msgs in
example (n : Nat) := (@List.nil Nat).foo