From d1e647e025e428ba765b2b56f57846193f141e07 Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Sat, 26 Oct 2024 10:06:29 +0200 Subject: [PATCH] [TS] Prevent generics to be duplicated (#3942) --- src/Fable.Cli/CHANGELOG.md | 1 + src/Fable.Transforms/Fable2Babel.fs | 1 + tests/Js/Main/DictionaryTests.fs | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/Fable.Cli/CHANGELOG.md b/src/Fable.Cli/CHANGELOG.md index 240427a312..ef70e9d49e 100644 --- a/src/Fable.Cli/CHANGELOG.md +++ b/src/Fable.Cli/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [JS/TS/Python/Rust] Fixed String.StartsWith/EndsWith (#3934) (by @ncave) * [All/Rust] Removed Regex.Replace from hot paths (by @ncave) * [JS] Fix regression, generate `let` variable when using `import` on a private mutable variable (by @MangelMaxime) +* [TS] Prevent generics to be duplicated (by @MangelMaxime) ## 4.22.0 - 2024-10-02 diff --git a/src/Fable.Transforms/Fable2Babel.fs b/src/Fable.Transforms/Fable2Babel.fs index c0d9bbf1e3..3f81237302 100644 --- a/src/Fable.Transforms/Fable2Babel.fs +++ b/src/Fable.Transforms/Fable2Babel.fs @@ -565,6 +565,7 @@ module Annotation = TypeParameter.typeParameter (name, ?bound = bound) |> Some | _ -> None ) + |> Array.distinct let makeTypeParamInstantiation (com: IBabelCompiler) ctx genArgs = if List.isEmpty genArgs then diff --git a/tests/Js/Main/DictionaryTests.fs b/tests/Js/Main/DictionaryTests.fs index 30a1385fb8..29d7fb1f51 100644 --- a/tests/Js/Main/DictionaryTests.fs +++ b/tests/Js/Main/DictionaryTests.fs @@ -12,6 +12,17 @@ type MyRecord = { a: int } type R = { i: int; s: string } +type Table<'K,'V when 'K:equality> () = + + let dic = new Dictionary<'K,'V>() + + let addKeyValue key value = + dic.[key] <- value + + member _.add key value = + addKeyValue key value + + member _.Dic = dic let tests = testList "Dictionaries" [ testCase "Dictionary KeyValuePattern works" <| fun () -> // See #509 @@ -251,4 +262,11 @@ let tests = equal cache.[typeof] 1 equal cache.[typeof] 2 equal cache.[typeof] 3 + + testCase "Check that generics are not duplicated " <| fun _ -> // See #3911 + let table = Table<_,_>() + table.add "A" 1 + table.add "B" 2 + table.add "C" 3 + table.Dic.Count |> equal 3 ]