Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #1310 from shanecharles/fix/bug1274
Browse files Browse the repository at this point in the history
Ignore any extra args to printf.
  • Loading branch information
vasily-kirichenko committed Jan 4, 2016
2 parents a103041 + 990d017 commit 528c60e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/FSharpVSPowerTools.Core/PrintfSpecifiersUsageGetter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ let getAll (input: ParseAndCheckResults) (onError: string -> unit): PrintfSpecif
l |> Array.sortBy startPos |]
|> Array.concat

let m = min func.Args.Length ownSpecifiers.Length

let uses =
func.Args
|> prioritizeArgPos ownSpecifiers.[0].Start
|> Array.zip (ownSpecifiers.[0..func.Args.Length - 1] |> Array.sortBy startPos)
|> function args -> args.[0..m - 1]
|> Array.zip (ownSpecifiers.[0..m - 1] |> Array.sortBy startPos)
|> Array.map (fun (specifier, arg) -> { SpecifierRange = specifier; ArgumentRange = arg })
restSpecifiers, uses :: acc
) (specifierRanges, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,40 @@ let ``forward pipe 3 deconstructs tuple with right hand argument``() =
=> [2, [(24, 26), (37, 38)
(27, 29), (1, 2)
(30, 32), (4, 5)
(33, 35), (7, 8)]]
(33, 35), (7, 8)]]

[<Test>]
let ``too many args should ignore extra args``() =
"""
printf "%d" 1 2
"""
=> [2, [(8, 10), (12, 13)]]

[<Test>]
let ``too many args with forward-pipe should ignore extra args``() =
"""
3 |> printf "%d" 1 2
"""
=> [2, [(13, 15), (17, 18)]]

[<Test>]
let ``too many args with forward-pipe 2 should ignore extra args``() =
"""
(2, 3) ||> printf "%d %d" 1
"""
=> [2, [(19, 21), (26, 27)
(22, 24), (1, 2)]]

[<Test>]
let ``backwards pipe with equal specifiers and args``() =
"""
ignore <| sprintf "%d" 1
"""
=> [2, [(19, 21), (23, 24)]]

[<Test>]
let ``backwards pipe with too many args``() =
"""
ignore <| sprintf "%d" 1 2
"""
=> [2, [(19, 21), (23, 24)]]

0 comments on commit 528c60e

Please sign in to comment.