dotnet / dotnet/fsharp

A namespace sharing the same name as a module with ModuleSuffix *when the namespace is declared first* ~~declared in the same file~~ is not visible

Open
#14,799 11 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking-NameResolution Feature Request Needs-RFC
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

If there is a namespace which shares a name with a module, the namespace isn't visible in the project when the namespace and *the namespace is declared before the module* ~~are declared the same file~~ (see https://github.com/dotnet/fsharp/issues/14798 for a similar bug when they're declared in separate files).

**Repro steps**

Provide the steps required to reproduce the problem:

1. Create a module and a namespace with the same name (the ModuleSuffix attribute is required for this to compile. Not sure if it should be)
```fsharp
namespace NamespaceModuleCollision

[]
module TopLevel =

let test = 5

namespace NamespaceModuleCollision.TopLevel
module Sub =

let test2 = 5
```
2. Attempt to use the values in the modules in a different file in the same project
```fsharp
module library

let _ = NamespaceModuleCollision.TopLevel.test
let _ = NamespaceModuleCollision.TopLevel.Sub.test2 //error

open NamespaceModuleCollision.TopLevel
open NamespaceModuleCollision.TopLevel.Sub //error

let _ = test2 //obviously has an error since the module can't be opened
```
If possible attach a zip file with the repro case. This often makes it easier for others to reproduce.
The zip file should ideally represent the situation just before the call/step that is problematic.

**Expected behavior**

The values in both the modules are accessible.

**Actual behavior**
Compiler errors when attempting to access the values in the 'Sub' module:

error FS0039: The value, constructor, namespace or type 'Sub' is not defined.
error FS0039: The namespace 'Sub' is not defined.
error FS0039: The value or constructor 'test2' is not defined. Maybe you want one of the following:↔ test↔ Text

[library.zip](https://github.com/dotnet/fsharp/files/10818591/library.zip)

**Known workarounds**

1. Declare the module and namespace in different files, but note that this only fixes the problem within a project. The same issue exists when attempting to access the namespace in a different project. i.e. https://github.com/dotnet/fsharp/issues/14798

2. Change the name of the module or namespace.

**Related information**
Reproduced in a net7.0 project

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.