You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The dot ident notation currently cannot be used to refer to the function being recursively defined, and attempting to do so results in a confusing error message.
Currently when the identifier is not found in the environment, the expected type is unfolded and the identifier is then searched for in the namespace of the unfolded type. This means that fixing this bug (as done in #6602) can break code that relies on the fallback occurring for a dot ident with the same name as the current function.
This can occur when defining an alias to another type, and defining a function that just applies the function of the same name from the original type. For example, code such as the following will be broken by the change:
opaque f : Nat → Nat
defMyEq (x y : Nat) := f x = f y -- an example type which unfolds to EqdefMyEq.symm : MyEq x y → MyEq y x := .symm
In MyEq.symm, .symm currently cannot find MyEq.symm, so MyEq is unfolded and .symm resolves to Eq.symm. After fixing this bug, .symm will resolve to MyEq.symm, causing a termination error.
The fix for this pattern is simple: mark the definition as nonrec. This is consistent with the postfix dot notation:
defMyEq.symm (h : MyEq x y) : MyEq y x := h.symm -- fail to show termination
nonrec defMyEq.symm (h : MyEq x y) : MyEq y x := h.symm -- works
Thanks for the analysis, in particular that it needs the unfold-and-look-again ambiguity.
Especially since postfix dot notation works already as you suggest, I agree with your analysis and fix, and that the broken code was only working accidentally.
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
The dot ident notation currently cannot be used to refer to the function being recursively defined, and attempting to do so results in a confusing error message.
Steps to Reproduce
Expected behavior:
.id n
is equivalent toNat.id n
andn.id
, which both succeed with no errors.Actual behavior: The following error:
Versions
Lean 4.16.0-nightly-2025-01-10
Appears in Lean 4.0.0-m5
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: