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

go/format: crashes with "illegal line number" #33538

Closed
dsnet opened this issue Aug 8, 2019 · 3 comments

Comments

@dsnet
Copy link
Member

commented Aug 8, 2019

Using e37a1b1

Here's a succinct reproduction:

func main() {
	format.Source([]byte(`package main
import ("foo"
"bar")`))
}

This crashes with:

panic: illegal line number

goroutine 1 [running]:
go/token.(*File).LineStart(0xc0000a2120, 0x4, 0x0)
	/usr/local/go.tip/src/go/token/position.go:222 +0xf6
go/ast.sortSpecs(0xc0000a4040, 0xc0000aa000, 0xc0000920a0, 0x2, 0x2, 0x1a, 0x2, 0xe)
	/usr/local/go.tip/src/go/ast/import.go:119 +0x269
go/ast.SortImports(0xc0000a4040, 0xc0000aa000)
	/usr/local/go.tip/src/go/ast/import.go:39 +0x117
go/format.Source(0xc000098030, 0x21, 0x21, 0x0, 0x0, 0x0, 0x4f16a0, 0xc00007a058)
	/usr/local/go.tip/src/go/format/format.go:101 +0x1a3
main.main()
	/tmp/sandbox340049386/main.go:11 +0x70

Git bisect reports that this is broken by: CL/162337

\cc @agnivade @griesemer

@dsnet dsnet added this to the Go1.13 milestone Aug 8, 2019

@dsnet

This comment has been minimized.

Copy link
Member Author

commented Aug 8, 2019

Given that it's late in the cycle and that this seems like an isolated change, should we revert the CL and address it in Go1.14?

@gopherbot

This comment has been minimized.

Copy link

commented Aug 8, 2019

Change https://golang.org/cl/189379 mentions this issue: Revert "go/ast: fix SortImports to handle block comments"

@gopherbot

This comment has been minimized.

Copy link

commented Aug 16, 2019

Change https://golang.org/cl/190523 mentions this issue: cmd/gofmt: update TestRewrite to avoid future regressions

gopherbot pushed a commit that referenced this issue Aug 16, 2019

cmd/gofmt: update TestRewrite to avoid future regressions
CL 162337 changed go/ast to better handle block comments,
but was reverted because it introduced an off-by-one bug.
This CL adds a test case to enforce the correct behavior
so that future changes do not break this again.

Updates #18929
Updates #33538

Change-Id: I2d25c139d007f8db1091b7a48b1dd20c584e2699
Reviewed-on: https://go-review.googlesource.com/c/go/+/190523
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.