File tree Expand file tree Collapse file tree 5 files changed +56
-0
lines changed
Expand file tree Collapse file tree 5 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
103103 * ` DateTime.TryParse `
104104 * ` DateTime.SpecifyKind `
105105
106+ #### JavaScript
107+
108+ * [ GH-3715 ] ( https://github.com/fable-compiler/Fable/pull/3715 ) Add support for System.Array.Resize (by @chkn )
109+
106110## 4.9.0 - 2023-12-14
107111
108112### Fixed
Original file line number Diff line number Diff line change @@ -3369,6 +3369,22 @@ let arrays
33693369 )
33703370 |> Some
33713371 | " GetEnumerator" , Some arg, _ -> getEnumerator com r t arg |> Some
3372+ | " Resize" , None, args ->
3373+ let args =
3374+ args @ [ getZero com ctx ( List.head i.GenericArgs) ]
3375+ |> injectArg com ctx r " Array" " resize" i.GenericArgs
3376+
3377+ Helper.LibCall(
3378+ com,
3379+ " Array" ,
3380+ " resize" ,
3381+ Unit,
3382+ args,
3383+ i.SignatureArgTypes,
3384+ genArgs = i.GenericArgs,
3385+ ?loc = r
3386+ )
3387+ |> Some
33723388 | _ -> None
33733389
33743390let arrayModule
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ let fableReplacementsModules =
5050 " insertAt" , ( Types.arrayCons, 0 )
5151 " insertManyAt" , ( Types.arrayCons, 0 )
5252 " updateAt" , ( Types.arrayCons, 0 )
53+ " resize" , ( Types.arrayCons, 0 )
5354 ]
5455 " List" ,
5556 Map
Original file line number Diff line number Diff line change @@ -1405,3 +1405,29 @@ let updateAt
14051405 xs.[ i]
14061406
14071407 target
1408+
1409+ let resize
1410+ ( xs : byref < 'T []>)
1411+ ( newSize : int )
1412+ ( [<OptionalArgument>] zero : 'T option )
1413+ ( [<OptionalArgument; Inject>] cons : Cons < 'T >)
1414+ : unit
1415+ =
1416+ if newSize < 0 then
1417+ invalidArg " newSize" " The input must be non-negative."
1418+
1419+ let len = xs.Length
1420+
1421+ if newSize < len then
1422+ xs <- subArrayImpl xs 0 newSize
1423+
1424+ elif newSize > len then
1425+ let target = allocateArrayFromCons cons newSize
1426+ copyTo xs 0 target 0 len
1427+
1428+ xs <-
1429+ fillImpl
1430+ target
1431+ ( defaultArg zero Unchecked.defaultof<_>)
1432+ len
1433+ ( newSize - len)
Original file line number Diff line number Diff line change @@ -1190,4 +1190,13 @@ let tests =
11901190 equal c1 true
11911191 equal c2 - 1
11921192 equal c3 1
1193+
1194+ testCase " Array.Resize works" <| fun () ->
1195+ let mutable xs = [| 1 ; 2 ; 3 ; 4 ; 5 |]
1196+ Array.Resize(& xs, 3 )
1197+ xs |> equal [| 1 ; 2 ; 3 |]
1198+ Array.Resize(& xs, 7 )
1199+ xs |> equal [| 1 ; 2 ; 3 ; 0 ; 0 ; 0 ; 0 |]
1200+ Array.Resize(& xs, 0 )
1201+ xs |> equal [||]
11931202 ]
You can’t perform that action at this time.
0 commit comments