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

Offen
#14,799 11 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Area-Compiler-Checking-NameResolution Feature Request Needs-RFC
Vorherrschende Sprache
F#
Sterne
4.3k
Forks
877
Ø Merge
5 T. 11 Std.
Gemergte PRs (30 T.)
153

Beschreibung

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)
namespace NamespaceModuleCollision

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module TopLevel =

    let test = 5

namespace NamespaceModuleCollision.TopLevel
    module Sub =

        let test2 = 5
  1. Attempt to use the values in the modules in a different file in the same project
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

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das Problem anhand der F#-Snippets aus den Reproduktionsschritten nachzustellen, wobei der Namespace vor dem ModuleSuffix-Modul deklariert wird, und versuche anschließend, die gezeigten Zugriffe und Öffnungen aus einer anderen Datei vorzunehmen. Im Issue werden keine Quelldateien oder Tests genannt. Erledigt bedeutet, dass sowohl TopLevel.test als auch TopLevel.Sub.test2 ohne FS0039-Fehler zugänglich sind.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
fsharp
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
32/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.