Skip to content

Commit 4b89282

Browse files
committed
Fix printf parsing of [N] after # in verbs (fixes #26)
1 parent 2f09b52 commit 4b89282

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

errorlint/printf.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (pp *printfParser) parseVerb() (*verb, error) {
5959
return pp.parseVerb()
6060
case '+', '#':
6161
pp.next()
62+
fallthrough
6263
case '[':
6364
var err error
6465
index, err = pp.parseIndex()

errorlint/printf_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ func TestPrintfParser(t *testing.T) {
4242
{format: "v", index: -1},
4343
},
4444
},
45+
{
46+
format: "%v %#[1]v",
47+
verbs: []verb{
48+
{format: "v", index: -1},
49+
{format: "v", index: 1},
50+
},
51+
},
4552
}
4653

4754
for _, tc := range testCases {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package issues
2+
3+
import "fmt"
4+
5+
func main() {
6+
err := fmt.Errorf("%v %#[1]v", struct{ string }{})
7+
fmt.Println(err)
8+
}

0 commit comments

Comments
 (0)