leanprover / leanprover/lean4

`resolveUniqueNamespace` fails even when all namespace resolution candidates are equal

Open
#13,353 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
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
  1. Open a namespace ns and set it as the current namespace.
  2. Try to resolve as a unique namespace a name n such that ns ++ n is 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.