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

Aperta
#14,799 11 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Area-Compiler-Checking-NameResolution Feature Request Needs-RFC
Lingua principale
F#
Stelle
4.3k
Fork
876
Merge medio
5g 9h
PR unite (30g)
153

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia riproducendo il problema dagli snippet F# nei passaggi per la riproduzione, con il namespace dichiarato prima del modulo ModuleSuffix, quindi prova a eseguire gli accessi e le aperture mostrati da un altro file. Nell’issue non sono indicati file sorgente o test. È completato quando sia TopLevel.test sia TopLevel.Sub.test2 sono accessibili senza errori FS0039.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
fsharp
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
32/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.