From 9f758064e14d835dfef3ce48ff0743175dc9774c Mon Sep 17 00:00:00 2001 From: reacheight Date: Tue, 11 Jun 2019 18:08:59 +0300 Subject: [PATCH 1/4] fixed map3 misleading error message on different length lists --- src/fsharp/FSharp.Core/local.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fsharp/FSharp.Core/local.fs b/src/fsharp/FSharp.Core/local.fs index 9fb452907f4..f42881d5c8d 100644 --- a/src/fsharp/FSharp.Core/local.fs +++ b/src/fsharp/FSharp.Core/local.fs @@ -294,16 +294,16 @@ module internal List = | [], xs2 -> invalidArgDifferentListLength "list1" "list2" xs2.Length | xs1, [] -> invalidArgDifferentListLength "list2" "list1" xs1.Length - let rec map3ToFreshConsTail cons (f:OptimizedClosures.FSharpFunc<_, _, _, _>) xs1 xs2 xs3 = + let rec map3ToFreshConsTail cons (f:OptimizedClosures.FSharpFunc<_, _, _, _>) xs1 xs2 xs3 cut = match xs1, xs2, xs3 with | [], [], [] -> setFreshConsTail cons [] | h1 :: t1, h2 :: t2, h3 :: t3 -> let cons2 = freshConsNoTail (f.Invoke(h1, h2, h3)) setFreshConsTail cons cons2 - map3ToFreshConsTail cons2 f t1 t2 t3 + map3ToFreshConsTail cons2 f t1 t2 t3 (cut + 1) | xs1, xs2, xs3 -> - invalidArg3ListsDifferent "list1" "list2" "list3" xs1.Length xs2.Length xs3.Length + invalidArg3ListsDifferent "list1" "list2" "list3" (xs1.Length + cut) (xs2.Length + cut) (xs3.Length + cut) let map3 mapping xs1 xs2 xs3 = match xs1, xs2, xs3 with @@ -311,7 +311,7 @@ module internal List = | h1 :: t1, h2 :: t2, h3 :: t3 -> let f = OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt(mapping) let cons = freshConsNoTail (f.Invoke(h1, h2, h3)) - map3ToFreshConsTail cons f t1 t2 t3 + map3ToFreshConsTail cons f t1 t2 t3 0 cons | xs1, xs2, xs3 -> invalidArg3ListsDifferent "list1" "list2" "list3" xs1.Length xs2.Length xs3.Length From f42e8eda291e3cacb31b1baefb1b7102612e40fb Mon Sep 17 00:00:00 2001 From: reacheight Date: Tue, 11 Jun 2019 20:37:46 +0300 Subject: [PATCH 2/4] fixed previous fix bug --- src/fsharp/FSharp.Core/local.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fsharp/FSharp.Core/local.fs b/src/fsharp/FSharp.Core/local.fs index f42881d5c8d..0f5c69160d0 100644 --- a/src/fsharp/FSharp.Core/local.fs +++ b/src/fsharp/FSharp.Core/local.fs @@ -311,7 +311,7 @@ module internal List = | h1 :: t1, h2 :: t2, h3 :: t3 -> let f = OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt(mapping) let cons = freshConsNoTail (f.Invoke(h1, h2, h3)) - map3ToFreshConsTail cons f t1 t2 t3 0 + map3ToFreshConsTail cons f t1 t2 t3 1 cons | xs1, xs2, xs3 -> invalidArg3ListsDifferent "list1" "list2" "list3" xs1.Length xs2.Length xs3.Length From befc4f6fe79ef48954761b05bf46d74e2d254185 Mon Sep 17 00:00:00 2001 From: reacheight Date: Tue, 11 Jun 2019 20:59:26 +0300 Subject: [PATCH 3/4] added map3 exception message test --- .../Microsoft.FSharp.Collections/ListModule2.fs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs index 63ae937b561..2a6b475c44a 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs @@ -102,7 +102,16 @@ type ListModule02() = let longerList = [1; 2] CheckThrowsArgumentException (fun () -> List.map3 funcInt shortList shortList longerList |> ignore) CheckThrowsArgumentException (fun () -> List.map3 funcInt shortList longerList shortList |> ignore) - CheckThrowsArgumentException (fun () -> List.map3 funcInt shortList shortList longerList |> ignore) + CheckThrowsArgumentException (fun () -> List.map3 funcInt shortList shortList longerList |> ignore) + + // exception message checking + let expectedMessage = + "The lists had different lengths.\n" + + sprintf " list1.Length = %i, list2.Length = %i, list3.Length = %i\n" shortList.Length shortList.Length longerList.Length + + "Parameter name: list1, list2, list3" + let ex = Assert.Throws(typeof, + (fun () -> List.map3 funcInt shortList shortList longerList |> ignore)) + Assert.AreEqual(expectedMessage, ex.Message) // empty List let resultEpt = List.map3 funcInt List.empty List.empty List.empty From fba0519be9d0ce84dc90e7e128acdf26c1e4c791 Mon Sep 17 00:00:00 2001 From: reacheight Date: Tue, 11 Jun 2019 22:42:02 +0300 Subject: [PATCH 4/4] fixed map3 exception message test --- .../FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs index 2a6b475c44a..342d5678bf2 100644 --- a/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs +++ b/tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/ListModule2.fs @@ -107,8 +107,8 @@ type ListModule02() = // exception message checking let expectedMessage = "The lists had different lengths.\n" + - sprintf " list1.Length = %i, list2.Length = %i, list3.Length = %i\n" shortList.Length shortList.Length longerList.Length + - "Parameter name: list1, list2, list3" + sprintf " list1.Length = %i, list2.Length = %i, list3.Length = %i" shortList.Length shortList.Length longerList.Length + + Environment.NewLine + "Parameter name: list1, list2, list3" let ex = Assert.Throws(typeof, (fun () -> List.map3 funcInt shortList shortList longerList |> ignore)) Assert.AreEqual(expectedMessage, ex.Message)