From 1d70589d6acdaeafb1da6ef85c2eec2cc8c0b5f6 Mon Sep 17 00:00:00 2001 From: Petr Pokorny Date: Tue, 16 Aug 2022 20:15:58 +0200 Subject: [PATCH 1/2] Custom equality on ModuleOrNamespaceKind (#13693) --- src/Compiler/TypedTree/TypedTree.fs | 17 ++++++++++ src/Compiler/TypedTree/TypedTree.fsi | 1 + .../ModuleDefinitions/ModuleDefinitions.fs | 33 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 3b328134868..51856ca7cb1 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -472,6 +472,7 @@ exception UndefinedName of exception InternalUndefinedItemRef of (string * string * string -> int * string) * string * string * string +[] type ModuleOrNamespaceKind = /// Indicates that a module is compiled to a class with the "Module" suffix added. @@ -485,6 +486,22 @@ type ModuleOrNamespaceKind = /// Indicates that the sourcecode had a namespace. /// If false, this namespace was implicitly constructed during type checking. isExplicit: bool + + override this.Equals other = + match other with + | :? ModuleOrNamespaceKind as kind -> + match this, kind with + | FSharpModuleWithSuffix, FSharpModuleWithSuffix + | ModuleOrType, ModuleOrType + | Namespace _, Namespace _ -> true + | _ -> false + | _ -> false + + override this.GetHashCode () = + match this with + | FSharpModuleWithSuffix -> 0 + | ModuleOrType -> 1 + | Namespace _ -> 2 /// A public path records where a construct lives within the global namespace /// of a CCU. diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index d2a23e73038..6251c7a0ae5 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -292,6 +292,7 @@ exception UndefinedName of depth: int * error: (string -> string) * id: Ident * exception InternalUndefinedItemRef of (string * string * string -> int * string) * string * string * string +[] type ModuleOrNamespaceKind = /// Indicates that a module is compiled to a class with the "Module" suffix added. diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicTypeAndModuleDefinitions/ModuleDefinitions/ModuleDefinitions.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicTypeAndModuleDefinitions/ModuleDefinitions/ModuleDefinitions.fs index af33f5c0f1e..65d694c9647 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicTypeAndModuleDefinitions/ModuleDefinitions/ModuleDefinitions.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicTypeAndModuleDefinitions/ModuleDefinitions/ModuleDefinitions.fs @@ -318,3 +318,36 @@ module ModuleDefinitions = |> withReferences [libFoo2; libFoo1] |> verifyCompileAndRun |> shouldSucceed + + [] + let ``Regression: compilation error with private types in namespace used in a different file`` () = + let types = + """ + namespace FsErrorRepro + + type private Blah = { Number: int } + """ + let example = + """ + [] + module FsErrorRepro.Example + + let dummy (blahNum: int) = + let blah : Blah = { Number = blahNum } + printf $"%i{blah.Number}" + """ + let program = + """ + module FsErrorRepro.Main + + [] + let main _ = + Example.dummy 15 + 0 + """ + + FSharp types + |> withAdditionalSourceFiles [SourceCodeFileKind.Create("example.fs", example) + SourceCodeFileKind.Create("program.fs", program)] + |> compile + |> shouldSucceed From 137a9f1a9aa676145ff45a35406ee2e818d9af6d Mon Sep 17 00:00:00 2001 From: Vlad Zarytovskii Date: Wed, 14 Sep 2022 19:41:18 +0200 Subject: [PATCH 2/2] Fix nuget warning --- .../Microsoft.FSharp.Compiler.csproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.FSharp.Compiler/Microsoft.FSharp.Compiler.csproj b/src/Microsoft.FSharp.Compiler/Microsoft.FSharp.Compiler.csproj index a16bc1310ee..62c328c110e 100644 --- a/src/Microsoft.FSharp.Compiler/Microsoft.FSharp.Compiler.csproj +++ b/src/Microsoft.FSharp.Compiler/Microsoft.FSharp.Compiler.csproj @@ -9,6 +9,13 @@ .NET Core compatible version of the F# compiler fsc.exe. /blob/main/release-notes.md#FSharp-Tools-$(FSProductVersionReleaseNotesVersion) true + + $(NoWarn);NU1505