-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dot ident notation cannot refer to recursive call #6601
Comments
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. opaque f : Nat → Nat
def MyEq (x y : Nat) := f x = f y -- an example type which unfolds to Eq
def MyEq.symm : MyEq x y → MyEq y x := .symm In The fix for this pattern is simple: mark the definition as def MyEq.symm (h : MyEq x y) : MyEq y x := h.symm -- fail to show termination
nonrec def MyEq.symm (h : MyEq x y) : MyEq y x := h.symm -- works This pattern of delegating to the same function name in the original type occurs in batteries and mathlib, for example in https://github.com/leanprover-community/batteries/blob/66225aab4f6bd1687053b03916105f7cab140507/Batteries/Data/UnionFind/Lemmas.lean#L100-L101. All of the breakage in |
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. Thanks for that! |
This PR allows the dot ident notation to resolve to the current definition, or to any of the other definitions in the same mutual block. Existing code that uses dot ident notation may need to have `nonrec` added if the ident has the same name as the definition. Closes #6601
This PR allows the dot ident notation to resolve to the current definition, or to any of the other definitions in the same mutual block. Existing code that uses dot ident notation may need to have `nonrec` added if the ident has the same name as the definition. Closes leanprover#6601
This PR allows the dot ident notation to resolve to the current definition, or to any of the other definitions in the same mutual block. Existing code that uses dot ident notation may need to have `nonrec` added if the ident has the same name as the definition. Closes leanprover#6601
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: