diff --git a/src/Compiler/Driver/GraphChecking/TrieMapping.fs b/src/Compiler/Driver/GraphChecking/TrieMapping.fs index bfab87f9bec..e34939abac1 100644 --- a/src/Compiler/Driver/GraphChecking/TrieMapping.fs +++ b/src/Compiler/Driver/GraphChecking/TrieMapping.fs @@ -70,6 +70,14 @@ let mergeTrieNodes (defaultChildSize: int) (tries: TrieNode array) = TrieNodeInfo.Namespace (filesThatExposeTypes = otherFiles; filesDefiningNamespaceWithoutTypes = otherFilesWithoutTypes) -> currentFilesThatExposeTypes.UnionWith otherFiles currentFilesWithoutTypes.UnionWith otherFilesWithoutTypes + // Edge case scenario detected in https://github.com/dotnet/fsharp/issues/15985 + | TrieNodeInfo.Namespace (filesThatExposeTypes = currentFilesThatExposeTypes), TrieNodeInfo.Module (_name, file) -> + // Keep the namespace (as it can still have nested children). + currentFilesThatExposeTypes.Add file |> ignore + | TrieNodeInfo.Module (_name, file), TrieNodeInfo.Namespace (filesThatExposeTypes = currentFilesThatExposeTypes) -> + currentFilesThatExposeTypes.Add file |> ignore + // Replace the module in favour of the namespace (which can hold nested children). + root.Children[ k ] <- v | _ -> () for kv in v.Children do diff --git a/tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/Scenarios.fs b/tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/Scenarios.fs index 7931861dcfb..a60e8e7c116 100644 --- a/tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/Scenarios.fs +++ b/tests/FSharp.Compiler.ComponentTests/TypeChecks/Graph/Scenarios.fs @@ -688,4 +688,66 @@ module ColdTasks = """ (set [| 0; 2 |]) ] + scenario + "ModuleSuffix clash" + [ + sourceFile + "A.fs" + """ +namespace F.General +""" + Set.empty + sourceFile + "B.fs" + """ +[] +module F + +let br () = () +""" + Set.empty + + sourceFile + "C.fs" + """ +module S + +[] +let main _ = + F.br () + 0 +""" + (set [| 1 |]) + ] + scenario + "ModuleSuffix clash, module before namespace" + [ + sourceFile + "A.fs" + """ +[] +module F + +let br () = () +""" + Set.empty + sourceFile + "B.fs" + """ +namespace F.General +""" + Set.empty + + sourceFile + "C.fs" + """ +module S + +[] +let main _ = + F.br () + 0 +""" + (set [| 0 |]) + ] ]