lean4-htt/tests/lean/run/invalid_field_notation_unusable_param.lean
Kyle Miller 741347281c
fix: dot notation for recursive invocation of private definitions (#10120)
This PR fixes an issue where private definitions recursively invoked
using generalized field notation (dot notation) would give an "invalid
field" errors. It also fixes an issue where "invalid field notation"
errors would pretty print the name of the declaration with a `_private`
prefix.

Closes #10044
2025-08-25 22:55:08 +00:00

59 lines
1.7 KiB
Text

set_option linter.unusedVariables false
def Nat.bar (x : String) (x : Nat) (y : Nat) := x
/--
error: Invalid field notation: `Nat.bar` has a parameter with expected type
Nat
but it cannot be used
Note: The parameter `x` cannot be referred to by name because that function has a preceding parameter of the same name
Hint: Consider rewriting this application without field notation (e.g., `C.f x` instead of `x.f`) or changing the parameter names of the function to avoid this conflict
-/
#guard_msgs in
#check Nat.zero.bar
structure F where
f : Bool → Nat → Nat
def Nat.foo : F := { f := fun _ _ => 0 }
section
local instance : CoeFun F (fun _ => Bool → Nat → Nat) where
coe x := fun (a : Bool) (b : Nat) => x.f a b
/--
error: Invalid field notation: `Nat.foo.f` (coerced from `Nat.foo`) has a parameter with expected type
Nat
but it cannot be used
Note: Field notation cannot refer to parameter `b` by name because that constant was coerced to a function
Hint: Consider rewriting this application without field notation (e.g., `C.f x` instead of `x.f`)
-/
#guard_msgs in #check Nat.zero.foo
/-- info: (fun a b => Nat.foo.f a b) true Nat.zero : Nat -/
#guard_msgs in #check Nat.zero.foo true
end
section
local instance : CoeFun F (fun _ => Bool → Nat → Nat) where
coe x := fun _ _ => 0
/--
error: Invalid field notation: `fun x x => 0` (coerced from `Nat.foo`) has a parameter with expected type
Nat
but it cannot be used
Hint: Consider rewriting this application without field notation (e.g., `C.f x` instead of `x.f`)
-/
#guard_msgs in #check Nat.zero.foo
/-- info: (fun x x => 0) true Nat.zero : Nat -/
#guard_msgs in #check Nat.zero.foo true
end