From 9c9ca73dac079c5c28461834abfd9335aee5702f Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 6 Jul 2023 14:07:59 +0200 Subject: [PATCH] Add check for type redefinition When using the debugger it may occur that the same type is loaded from different assemblies. This commit adds checks to avoid conflicts and duplication in such scenarios. --- src/Libs/FShade.Imperative/Compiler.fs | 4 ++-- src/Libs/FShade.Imperative/ModuleCompiler.fs | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Libs/FShade.Imperative/Compiler.fs b/src/Libs/FShade.Imperative/Compiler.fs index a7cb036..56a14ee 100644 --- a/src/Libs/FShade.Imperative/Compiler.fs +++ b/src/Libs/FShade.Imperative/Compiler.fs @@ -1388,13 +1388,13 @@ module Compiler = | NewTuple(fields) -> let! s = State.get - let! ctor = e.Type |> Constructors.tuple s.moduleState.backend |> CompilerState.useCtor e.Type + let! ctor = e.Type |> Constructors.tuple s.moduleState.backend |> CompilerState.useCtor (typeName e.Type) let! fields = fields |> List.mapS toCExprS |>> List.toArray return CCall(ctor, fields) | NewRecord(t, fields) -> let! s = State.get - let! ctor = t |> Constructors.record s.moduleState.backend |> CompilerState.useCtor t + let! ctor = t |> Constructors.record s.moduleState.backend |> CompilerState.useCtor (typeName t) let! fields = fields |> List.mapS toCExprS |>> List.toArray return CCall(ctor, fields) diff --git a/src/Libs/FShade.Imperative/ModuleCompiler.fs b/src/Libs/FShade.Imperative/ModuleCompiler.fs index b85fa41..c4f7ae8 100644 --- a/src/Libs/FShade.Imperative/ModuleCompiler.fs +++ b/src/Libs/FShade.Imperative/ModuleCompiler.fs @@ -419,7 +419,21 @@ module ModuleCompiler = let set = System.Collections.Generic.HashSet() for t in graphs do visit set t - set |> Seq.toArray |> Array.sort |> Array.toList |> List.choose (fun t -> t.Definition) + set + |> Seq.toArray + |> Array.sort + |> Array.toList + |> List.choose (fun t -> t.Definition) + |> List.distinct + |> List.groupBy (fun (CStructDef(n, _)) -> n) + |> List.map (fun (n, defs) -> + if defs.Length > 1 then + let nl = Environment.NewLine + let defs = defs |> List.map string |> String.concat nl + failwithf $"[FShade] Multiple conflicting type definitions with name {n}:{nl}{defs}" + else + defs.Head + ) let ofTypes (types : list) = let compile =