Skip to content

Commit

Permalink
printf: fix empty interpolation string evaluates to null in printf env
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed May 2, 2020
1 parent 49ba592 commit 7f39617
Showing 1 changed file with 57 additions and 54 deletions.
111 changes: 57 additions & 54 deletions src/fsharp/FSharp.Core/printf.fs
Original file line number Diff line number Diff line change
Expand Up @@ -287,60 +287,63 @@ module internal PrintfImpl =
member env.RunSteps (args: obj[], steps: Step[]) =
let mutable argIndex = 0

for step in steps do
match step with
| Step (prefix, conv1) ->
env.WriteSkipEmpty(prefix)
env.Write(&argIndex, args, conv1)

| StepString prefix ->
env.WriteSkipEmpty(prefix)

| StepLittleT(prefix) ->
env.WriteSkipEmpty prefix
let farg = args.[argIndex]
argIndex <- argIndex + 1
let f = farg :?> ('State -> 'Residue)
env.WriteT(f env.State)

| StepLittleA(prefix) ->
env.WriteSkipEmpty prefix
let farg = args.[argIndex]
argIndex <- argIndex + 1
let arg = args.[argIndex]
argIndex <- argIndex + 1
let f = farg :?> ('State -> obj -> 'Residue)
env.WriteT(f env.State arg)

| StepStar1(prefix, conv) ->
env.WriteSkipEmpty prefix
let star1 = args.[argIndex] :?> int
argIndex <- argIndex + 1
let arg1 = args.[argIndex]
argIndex <- argIndex + 1
env.Write (conv arg1 star1)

| StepPercentStar1(prefix) ->
//let _star1 = args.[argIndex] :?> int
argIndex <- argIndex + 1
env.WriteSkipEmpty prefix
env.Write("%")

| StepStar2(prefix, conv) ->
env.WriteSkipEmpty prefix
let star1 = args.[argIndex] :?> int
argIndex <- argIndex + 1
let star2 = args.[argIndex] :?> int
argIndex <- argIndex + 1
let arg1 = args.[argIndex]
argIndex <- argIndex + 1
env.Write (conv arg1 star1 star2)

| StepPercentStar2(prefix) ->
env.WriteSkipEmpty prefix
//let _star1 = args.[argIndex] :?> int
argIndex <- argIndex + 2
env.Write("%")
match steps with
| [| StepString one |] -> env.Write(one)
| _ ->
for step in steps do
match step with
| Step (prefix, conv1) ->
env.WriteSkipEmpty(prefix)
env.Write(&argIndex, args, conv1)

| StepString prefix ->
env.WriteSkipEmpty(prefix)

| StepLittleT(prefix) ->
env.WriteSkipEmpty prefix
let farg = args.[argIndex]
argIndex <- argIndex + 1
let f = farg :?> ('State -> 'Residue)
env.WriteT(f env.State)

| StepLittleA(prefix) ->
env.WriteSkipEmpty prefix
let farg = args.[argIndex]
argIndex <- argIndex + 1
let arg = args.[argIndex]
argIndex <- argIndex + 1
let f = farg :?> ('State -> obj -> 'Residue)
env.WriteT(f env.State arg)

| StepStar1(prefix, conv) ->
env.WriteSkipEmpty prefix
let star1 = args.[argIndex] :?> int
argIndex <- argIndex + 1
let arg1 = args.[argIndex]
argIndex <- argIndex + 1
env.Write (conv arg1 star1)

| StepPercentStar1(prefix) ->
//let _star1 = args.[argIndex] :?> int
argIndex <- argIndex + 1
env.WriteSkipEmpty prefix
env.Write("%")

| StepStar2(prefix, conv) ->
env.WriteSkipEmpty prefix
let star1 = args.[argIndex] :?> int
argIndex <- argIndex + 1
let star2 = args.[argIndex] :?> int
argIndex <- argIndex + 1
let arg1 = args.[argIndex]
argIndex <- argIndex + 1
env.Write (conv arg1 star1 star2)

| StepPercentStar2(prefix) ->
env.WriteSkipEmpty prefix
//let _star1 = args.[argIndex] :?> int
argIndex <- argIndex + 2
env.Write("%")

env.Finish()

Expand Down

0 comments on commit 7f39617

Please sign in to comment.