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

58 lines
1.6 KiB
Text

/-!
# Tests of generalized field notation in recursive functions
-/
namespace Test1
/-!
We do not consider dot notation for local decls corresponding to recursive functions being defined.
The following example would not be elaborated correctly without this case.
-/
def foo.aux := 1
def foo : Nat → Nat
| n => foo.aux -- should not be interpreted as `(foo).bar`
end Test1
namespace Issue10044
/-!
Private recursive definitions on private types.
-/
private inductive IfExpr
| lit : Bool → IfExpr
| var : Nat → IfExpr
| ite : IfExpr → IfExpr → IfExpr → IfExpr
namespace IfExpr
private def hasNestedIf : IfExpr → Bool
| lit _ => false
| var _ => false
| ite (ite _ _ _) _ _ => true
| ite _ t e => t.hasNestedIf || e.hasNestedIf --- Invalid field `hasNestedIf`
end IfExpr
end Issue10044
/-!
Checking that the name of the function being defined is reported.
-/
/--
error: Invalid field notation: Function `testError1` does not have a usable parameter of type `Bool` for which to substitute `true`
Note: Such a parameter must be explicit, or implicit with a unique name, to be used by field notation
-/
#guard_msgs in
def Bool.testError1 (n : Nat) : Nat :=
(true).testError1
/-!
Checking that the name of the function being defined is reported, even if it is a `private` definition.
This used to print with a `_private` prefix.
-/
/--
error: Invalid field notation: Function `testError2` does not have a usable parameter of type `Bool` for which to substitute `true`
Note: Such a parameter must be explicit, or implicit with a unique name, to be used by field notation
-/
#guard_msgs in
private def Bool.testError2 (n : Nat) : Nat :=
(true).testError2