You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[mateusz@arch go (master)]$ go test -run NotNewl -v go/printer -v
=== RUN TestFormFeedNotNewline
printer_test.go:887: source:
package A
import("a"/*
*/
"bb")
formatted as:
package A
import (
"a" /*
*/"bb"
)
printer_test.go:888: test.go:4:11: expected ';', found "bb" (and 1 more errors)
printer_test.go:887: source:
package A
func test() {"a"/*
*/
"bb"}
formatted as:
package A
func test() {
"a" /*
*/"bb"
}
printer_test.go:888: test.go:4:11: expected ';', found "bb" (and 1 more errors)
This issue happens in the (*printer).print method.
next.Line is equal to 3 and p.pos.Line is also 3, which causes zero newlines to be inserted, this happens because the (*printer).writeString method treats \f as a newline and incorrectly increases the p.pos.Line field.
This is an unrealistic edge-case, found by a fuzzer.
Both of the go sources in the reproducer below, are parsed successfully, but the printed source (with
go/printer
) contains a syntax error:This issue happens in the
(*printer).print
method.go/src/go/printer/printer.go
Lines 1006 to 1020 in b521ebb
specifically here:
go/src/go/printer/printer.go
Line 1007 in b521ebb
next.Line
is equal to 3 andp.pos.Line
is also 3, which causes zero newlines to be inserted, this happens because the(*printer).writeString
method treats\f
as a newline and incorrectly increases thep.pos.Line
field.go/src/go/printer/printer.go
Lines 312 to 334 in b521ebb
This was a nightmare to debug, but it seems like a fix is a one-liner, will send a CL.
The text was updated successfully, but these errors were encountered: