Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed List.map3 misleading error message on different length lists #6980

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/fsharp/FSharp.Core/local.fs
Original file line number Diff line number Diff line change
Expand Up @@ -294,24 +294,24 @@ 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
| [], [], [] -> []
| 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArgumentException>,
(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
Expand Down