Skip to content

Commit bdb8427

Browse files
committed
Fix type declaration order when merging namespace fragments
1 parent 9b81e87 commit bdb8427

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed

src/fsharp/tast.fs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4712,35 +4712,34 @@ let NewClonedTycon orig = NewModifiedTycon (fun d -> d) orig
47124712
/// duplicate modules etc.
47134713
let CombineCcuContentFragments m l =
47144714

4715-
let CombineMaps f m1 m2 =
4716-
Map.foldBack (fun k v acc -> Map.add k (if Map.containsKey k m2 then f [v;Map.find k m2] else f [v]) acc) m1
4717-
(Map.foldBack (fun k v acc -> if Map.containsKey k m1 then acc else Map.add k (f [v]) acc) m2 Map.empty)
4718-
47194715
/// Combine module types when multiple namespace fragments contribute to the
47204716
/// same namespace, making new module specs as we go.
47214717
let rec CombineModuleOrNamespaceTypes path m (mty1:ModuleOrNamespaceType) (mty2:ModuleOrNamespaceType) =
47224718
match mty1.ModuleOrNamespaceKind,mty2.ModuleOrNamespaceKind with
47234719
| Namespace,Namespace ->
47244720
let kind = mty1.ModuleOrNamespaceKind
4721+
let tab1 = mty1.AllEntitiesByLogicalMangledName
4722+
let tab2 = mty2.AllEntitiesByLogicalMangledName
47254723
let entities =
4726-
(mty1.AllEntitiesByLogicalMangledName,mty2.AllEntitiesByLogicalMangledName)
4727-
||> CombineMaps (CombineEntityList path)
4724+
[ for e1 in mty1.AllEntities do
4725+
match tab2.TryFind e1.LogicalName with
4726+
| Some e2 -> yield CombineEntites path e1 e2
4727+
| None -> yield e1
4728+
for e2 in mty2.AllEntities do
4729+
match tab1.TryFind e2.LogicalName with
4730+
| Some _ -> ()
4731+
| None -> yield e2 ]
47284732

47294733
let vals = QueueList.append mty1.AllValsAndMembers mty2.AllValsAndMembers
47304734

4731-
ModuleOrNamespaceType(kind, vals, QueueList.ofList (NameMap.range entities))
4735+
ModuleOrNamespaceType(kind, vals, QueueList.ofList entities)
47324736

47334737
| Namespace, _ | _,Namespace ->
47344738
error(Error(FSComp.SR.tastNamespaceAndModuleWithSameNameInAssembly(textOfPath path),m))
47354739

47364740
| _->
47374741
error(Error(FSComp.SR.tastTwoModulesWithSameNameInAssembly(textOfPath path),m))
47384742

4739-
and CombineEntityList path l =
4740-
match l with
4741-
| h :: t -> List.fold (CombineEntites path) h t
4742-
| _ -> failwith "CombineEntityList"
4743-
47444743
and CombineEntites path (entity1:Entity) (entity2:Entity) =
47454744

47464745
match entity1.IsModuleOrNamespace, entity2.IsModuleOrNamespace with

tests/fsharp/core/tests_core.fs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,43 @@ module InternalsVisible =
907907
})
908908

909909

910+
// Repro for https://github.com/Microsoft/visualfsharp/issues/1298
911+
module FileOrder =
912+
913+
[<Test; FSharpSuiteTest("core/fileorder")>]
914+
let fileorder () = check (attempt {
915+
let { Directory = dir; Config = cfg } = testContext ()
916+
917+
let exec p = Command.exec dir cfg.EnvironmentVariables { Output = Inherit; Input = None; } p >> checkResult
918+
let fsc = Printf.ksprintf (Commands.fsc exec cfg.FSC)
919+
let peverify = Commands.peverify exec cfg.PEVERIFY "/nologo"
920+
let csc = Printf.ksprintf (Commands.csc exec cfg.CSC)
921+
let fsc_flags = cfg.fsc_flags
922+
923+
log "== Compiling F# Library and Code, when empty file libfile2.fs IS NOT included"
924+
do! fsc "%s -a --optimize -o:lib.dll " fsc_flags ["libfile1.fs"]
925+
926+
do! peverify "lib.dll"
927+
928+
do! fsc "%s -r:lib.dll -o:test.exe" fsc_flags ["test.fsx"]
929+
930+
do! peverify "test.exe"
931+
932+
do! exec ("."/"test.exe") ""
933+
934+
log "== Compiling F# Library and Code, when empty file libfile2.fs IS included"
935+
do! fsc "%s -a --optimize -o:lib2.dll " fsc_flags ["libfile1.fs"; "libfile2.fs"]
936+
937+
do! peverify "lib2.dll"
938+
939+
do! fsc "%s -r:lib2.dll -o:test2.exe" fsc_flags ["test.fsx"]
940+
941+
do! peverify "test2.exe"
942+
943+
do! exec ("."/"test2.exe") ""
944+
})
945+
946+
910947
module Interop =
911948

912949
let build cfg dir = attempt {

0 commit comments

Comments
 (0)