From 027e8c9b58bba85afef26a2869f2c805b20bb427 Mon Sep 17 00:00:00 2001 From: reacheight Date: Wed, 12 Jun 2019 00:13:29 +0300 Subject: [PATCH] fixed List.map3 misleading error message on different length lists (#6980) * fixed map3 misleading error message on different length lists * fixed previous fix bug * added map3 exception message test * fixed map3 exception message test --- src/fsharp/FSharp.Core/local.fs | 8 ++++---- .../Microsoft.FSharp.Collections/ListModule2.fs | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/fsharp/FSharp.Core/local.fs b/src/fsharp/FSharp.Core/local.fs index 9fb452907f4..0f5c69160d0 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 1 cons | xs1, xs2, xs3 -> invalidArg3ListsDifferent "list1" "list2" "list3" xs1.Length xs2.Length xs3.Length 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..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 @@ -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" 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) // empty List let resultEpt = List.map3 funcInt List.empty List.empty List.empty