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

Commitdbf7a9f

Browse files
authored
Merge pull request #3475 from syeerzy/master
fixed #3474 : change the sliceTake and sliceSkip behavior
2 parentsb083323 +94e9a21 commitdbf7a9f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,16 +245,26 @@ type ListType() =
245245
Assert.AreEqual(lst.[6..],([]: int list))
246246
CheckThrowsIndexOutRangException((fun _-> lst.[7..]|> ignore))
247247

248-
CheckThrowsIndexOutRangException((fun _-> lst.[..-1]|> ignore))
248+
249+
Assert.AreEqual(lst.[..(-1)],([]: int list))
249250
Assert.AreEqual(lst.[..0],[1])
250251
Assert.AreEqual(lst.[..1],[1;2])
251252
Assert.AreEqual(lst.[..2],[1;2;3])
252253
Assert.AreEqual(lst.[..3],[1;2;3;4])
253254
Assert.AreEqual(lst.[..4],[1;2;3;4;5])
254255
Assert.AreEqual(lst.[..5],[1;2;3;4;5;6])
255-
CheckThrowsIndexOutRangException((fun _-> lst.[..6]|> ignore))
256+
CheckThrowsIndexOutRangException((fun _-> lst.[..6]|> ignore))
257+
258+
Assert.AreEqual(lst.[0..(-1)],([]: int list))
259+
Assert.AreEqual(lst.[0..0],[1])
260+
Assert.AreEqual(lst.[0..1],[1;2])
261+
Assert.AreEqual(lst.[0..2],[1;2;3])
262+
Assert.AreEqual(lst.[0..3],[1;2;3;4])
263+
Assert.AreEqual(lst.[0..4],[1;2;3;4;5])
264+
Assert.AreEqual(lst.[0..5],[1;2;3;4;5;6])
265+
CheckThrowsIndexOutRangException((fun _-> lst.[0..6]|> ignore))
256266

257-
Assert.AreEqual(lst.[1..-1],([]: int list))
267+
Assert.AreEqual(lst.[1..(-1)],([]: int list))
258268
Assert.AreEqual(lst.[1..0],([]: int list))
259269
Assert.AreEqual(lst.[1..1],[2])
260270
Assert.AreEqual(lst.[1..2],[2;3])
@@ -270,8 +280,8 @@ type ListType() =
270280
Assert.AreEqual(lst.[3..1],([]: int list))
271281
Assert.AreEqual(lst.[4..1],([]: int list))
272282

273-
Assert.AreEqual(lst.[-3..-4],([]: int list))
274-
CheckThrowsIndexOutRangException((fun _-> lst.[-4..-3]|> ignore))
283+
Assert.AreEqual(lst.[-3..(-4)],([]: int list))
284+
CheckThrowsIndexOutRangException((fun _-> lst.[-4..(-3)]|> ignore))
275285

276286
letempty:obj list= List.empty
277287
Assert.AreEqual(empty.[*],([]: obj list))
@@ -280,4 +290,4 @@ type ListType() =
280290
CheckThrowsIndexOutRangException((fun _-> empty.[..0]|> ignore))
281291
CheckThrowsIndexOutRangException((fun _-> empty.[0..0]|> ignore))
282292
CheckThrowsIndexOutRangException((fun _-> empty.[0..1]|> ignore))
283-
CheckThrowsIndexOutRangException((fun _-> empty.[3..5]|> ignore))
293+
CheckThrowsIndexOutRangException((fun _-> empty.[3..5]|> ignore))

‎src/fsharp/FSharp.Core/prim-types.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,7 @@ namespace Microsoft.FSharp.Collections
31573157
// similar to 'take' but with n representing an index, not a number of elements
31583158
// and with exceptions matching array slicing
31593159
letsliceTake n l=
3160-
if n<0thenoutOfRange()
3160+
if n<0then[]else
31613161
match lwith
31623162
|[]-> outOfRange()
31633163
| x::xs->

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp