From 9e0969f41801786a70e373d6929571819788ff83 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 23 Nov 2016 18:38:27 +0100 Subject: [PATCH 1/2] try to reproduce #1644 --- .../Microsoft.FSharp.Collections/SeqModule2.fs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs index 6ab40a77af..099659788e 100644 --- a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs +++ b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs @@ -918,6 +918,14 @@ type SeqModule2() = for i = 11 to 20 do CheckThrowsArgumentException (fun () -> Seq.item i { 10 .. 20 } |> ignore) + [] + member this.``item should fail with correct number of missing elements``() = + try + Seq.item 0 (Array.zeroCreate 0) |> ignore + failwith "error expected" + with + | exn when exn.Message.Contains("seq was short by 1 element") -> () + [] member this.Of_Array() = // integer Seq From 1dee5d0867318961038958e5adc9a741f3aa695a Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 23 Nov 2016 18:44:28 +0100 Subject: [PATCH 2/2] Fix #1644 --- .../FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs | 6 ++++++ src/fsharp/FSharp.Core/seq.fs | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs index 099659788e..06b69feb34 100644 --- a/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs +++ b/src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Collections/SeqModule2.fs @@ -926,6 +926,12 @@ type SeqModule2() = with | exn when exn.Message.Contains("seq was short by 1 element") -> () + try + Seq.item 2 (Array.zeroCreate 0) |> ignore + failwith "error expected" + with + | exn when exn.Message.Contains("seq was short by 3 elements") -> () + [] member this.Of_Array() = // integer Seq diff --git a/src/fsharp/FSharp.Core/seq.fs b/src/fsharp/FSharp.Core/seq.fs index 31c70f57ee..d2cfe54622 100644 --- a/src/fsharp/FSharp.Core/seq.fs +++ b/src/fsharp/FSharp.Core/seq.fs @@ -64,9 +64,10 @@ namespace Microsoft.FSharp.Collections let rec nth index (e : IEnumerator<'T>) = if not (e.MoveNext()) then + let shortBy = index + 1 invalidArgFmt "index" "{0}\nseq was short by {1} {2}" - [|SR.GetString SR.notEnoughElements; index; (if index=1 then "element" else "elements")|] + [|SR.GetString SR.notEnoughElements; shortBy; (if shortBy = 1 then "element" else "elements")|] if index = 0 then e.Current else nth (index-1) e