Skip to content

Commit

Permalink
[TS] Prevent generics to be duplicated (fable-compiler#3942)
Browse files Browse the repository at this point in the history
  • Loading branch information
MangelMaxime authored Oct 26, 2024
1 parent 94cf161 commit d1e647e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/Js/Main/DictionaryTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -251,4 +262,11 @@ let tests =
equal cache.[typeof<int>] 1
equal cache.[typeof<string>] 2
equal cache.[typeof<int64>] 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
]

0 comments on commit d1e647e

Please sign in to comment.