Conflict with deeply nested rec function declarations
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Description
When declaring nested rec functions within inner functions with the same name, an Error <Outer function name>.<Nested function name> has already been declared is encountered.
Context
I was trying to encapsulate all my code in one definition, which lead to me deciding to nest a helper function under an already nested inner function which is where i encountered the error.
Steps to Reproduce
def outerFunction (x : Nat) : Nat :=
let innerFunction (x : Nat) :=
let rec helper (x : Nat) :=
helper x
helper x
let otherInnerFunction (x : Nat) :=
let rec helper (x : Nat) :=
x
helper x
funcA x
Expected behavior: Since the first helper is nested under innerFunction and the second helper is nested under otherInnerFunction, i expected this to compile normally.
Actual behavior: In reality this gave an error under the second helper outerFunction.helper has already been declared even though this is nested under otherInnerFunction and not directly under outerFunction
Versions
Lean 4.7.0
Windows 11 Pro, 23H2
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided nested rec reproduction on Lean 4.7.0 and confirm the duplicate-declaration error. Trace how the compiler handles the two nested helper declarations; done means the example compiles without the erroneous outerFunction.helper has already been declared error.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100