`resolveUniqueNamespace` fails even when all namespace resolution candidates are equal
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
resolveUniqueNamespace errors with "ambiguous namespace" if the candidates are not a singleton list. However, it can happen that the list is non-singleton, but contains all identical entries (for example, if the opened namespace appended to the current namespace is a namespace, and the open decls produce the same namespace). This affects e.g. open hiding occasionally, which relies on resolveUniqueNamespace.
This can happen when the current namespace is opened:
namespace Foo.Bar
-- register namespace(s)
end Foo.Bar
open Foo
namespace Foo
/-- error: ambiguous namespace `Bar`, possible interpretations: `[Foo.Bar, Foo.Bar]` -/
#guard_msgs in
open Bar hiding foo
Context
This occurs because in resolveNamespace we simply prepend any successful return of resolveNamespaceUsingScope? to what resolveNamespaceUsingOpenDecls gives us, even if it already exists in the list:
def resolveNamespace (env : Environment) (ns : Name) (openDecls : List OpenDecl) (id : Name) : List Name :=
match resolveNamespaceUsingScope? env id ns with
| some ns => ns :: resolveNamespaceUsingOpenDecls env id openDecls
| none => resolveNamespaceUsingOpenDecls env id openDecls
and then demand a singleton list inside of resolveUniqueNamespace.
Steps to Reproduce
- Open a namespace
nsand set it as the current namespace. - Try to resolve as a unique namespace a name
nsuch thatns ++ nis a namespace.
Expected behavior: We resolve to ns ++ n.
Actual behavior: We error, claiming that ns ++ n is ambiguous due to producing the resolutions [ns ++ n, ns ++ n].
Versions
Lean 4.31.0-nightly-2026-04-09
(Lean web)
Additional Information
The duplication in the output of resolveNamespace also results in duplicate OpenDecls in the scope after ordinary opens, but this doesn't seem to be an issue.
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
Start with the minimal Lean example in the issue and read resolveNamespace and resolveUniqueNamespace, especially how scope and open-declaration results are combined. Confirm the reproduced [Foo.Bar, Foo.Bar] case and use it as a regression test; done means the example resolves Foo.Bar without an ambiguous-namespace error.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 63/100