Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite10b8d0

Browse files
PatrickMcDonaldlatkin
authored andcommitted
truncate should not throw ArgumentException when count is negative
fixesdotnet#453closesdotnet#454
1 parent2044977 commite10b8d0

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ArrayModule2.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,8 @@ type ArrayModule2() =
939939
CheckThrowsArgumentNullException(fun()-> Array.truncate1null|> ignore)
940940

941941
// negative count
942-
CheckThrowsArgumentException(fun()-> Array.truncate-1[|1..5|]|> ignore)
942+
Assert.AreEqual([||], Array.truncate-1[|1..5|])
943+
Assert.AreEqual([||], Array.truncate System.Int32.MinValue[|1..5|])
943944

944945
()
945946

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ type ListModule02() =
815815
Assert.AreEqual([], List.truncate1[])
816816

817817
// negative count
818-
CheckThrowsArgumentException(fun()-> List.truncate-1[1..5]|> ignore)
818+
Assert.AreEqual([], List.truncate-1[1..5])
819+
Assert.AreEqual([], List.truncate System.Int32.MinValue[1..5])
819820

820821
()
821822

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,11 @@ type SeqModule2() =
15331533

15341534
// null Seq
15351535
CheckThrowsArgumentNullException(fun()-> Seq.truncate1null|> ignore)
1536+
1537+
// negative count
1538+
VerifySeqsEqual Seq.empty<| Seq.truncate-1(seq[1;2;4;5;7])
1539+
VerifySeqsEqual Seq.empty<| Seq.truncate System.Int32.MinValue(seq[1;2;4;5;7])
1540+
15361541
()
15371542

15381543
[<Test>]

‎src/fsharp/FSharp.Core/array.fs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,7 @@ namespace Microsoft.FSharp.Collections
10011001
[<CompiledName("Truncate")>]
10021002
lettruncate count(array:'T[])=
10031003
checkNonNull"array" array
1004-
if count<0then invalidArg"count"(SR.GetString(SR.inputMustBeNonNegative))
1005-
if count=0then empty
1004+
if count<=0then empty
10061005
else
10071006
letlen= array.Length
10081007
letcount'= Operators.min count len

‎src/fsharp/FSharp.Core/array.fsi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,6 @@ namespace Microsoft.FSharp.Collections
981981
///<param name="array">The input array.</param>
982982
///<returns>The result array.</returns>
983983
///<exception cref="System.ArgumentNullException">Thrown when the input array is null.</exception>
984-
///<exception cref="System.ArgumentException">Thrown when the count is negative.</exception>
985984
[<CompiledName("Truncate")>]
986985
val truncate:count:int->array:'T[]-> 'T[]
987986

‎src/fsharp/FSharp.Core/list.fsi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,6 @@ namespace Microsoft.FSharp.Collections
778778
///<param name="count">The maximum number of items to return.</param>
779779
///<param name="array">The input list.</param>
780780
///<returns>The result list.</returns>
781-
///<exception cref="System.ArgumentException">Thrown when the count is negative.</exception>
782781
[<CompiledName("Truncate")>]
783782
val truncate:count:int->list:'T list-> 'T list
784783

‎src/fsharp/FSharp.Core/local.fs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,16 @@ module internal List =
441441
truncateToFreshConsTail cons2(count-1) t
442442

443443
lettruncate count list=
444-
if count<0then invalidArg"count"(SR.GetString(SR.inputMustBeNonNegative))
445444
match listwith
446445
|[]-> list
447446
|_::([]as nil)->if count>0then listelse nil
448447
| h::t->
449-
if count=0then[]
448+
if count<=0then[]
450449
else
451450
letcons= freshConsNoTail h
452451
truncateToFreshConsTail cons(count-1) t
453452
cons
454-
453+
455454
let recunfoldToFreshConsTail cons f s=
456455
match f swith
457456
| None-> setFreshConsTail cons[]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp