Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Core/9.0.300.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Fixed
* Modified the behavior of `Array.insertManyAt` to return a copy of the original array when inserting an empty array. ([PR #18353](https://github.com/dotnet/fsharp/pull/18353))

### Added
* Added nullability annotations to `.Using` builder method for `async` and `task` builders ([PR #18292](https://github.com/dotnet/fsharp/pull/18292))
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Core/array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ module Array =
let valuesArray = Seq.toArray values

if valuesArray.Length = 0 then
source
source.Clone() :?> 'T array
else
let length = source.Length + valuesArray.Length
let result = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked length
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Core/array.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -3080,7 +3080,7 @@ module Array =
/// <param name="values">The values to insert.</param>
/// <param name="source">The input array.</param>
///
/// <returns>The result array.</returns>
/// <returns>A new array (even if values is empty).</returns>
///
/// <exception cref="T:System.ArgumentException">Thrown when index is below 0 or greater than source.Length.</exception>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,4 +1679,10 @@ type ArrayModule2() =
// empty list & out of bounds
Assert.AreEqual([0; 0], Array.insertManyAt 0 [0; 0] [||])
CheckThrowsArgumentException (fun () -> Array.insertManyAt -1 [0; 0] [|1|] |> ignore)
CheckThrowsArgumentException (fun () -> Array.insertManyAt 2 [0; 0] [|1|] |> ignore)
CheckThrowsArgumentException (fun () -> Array.insertManyAt 2 [0; 0] [|1|] |> ignore)

// Do not return the original array when inserting an empty array
let originalArr = [| 1; 2; 3 |]
let insertionEmptyResultArr = Array.insertManyAt 3 [| |] originalArr
insertionEmptyResultArr[0] <- 3
Assert.AreEqual([| 1; 2; 3 |], originalArr)
Loading