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
Closed

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

dsnet opened this issue Aug 8, 2019 · 3 comments

Comments

@dsnet
Copy link
Member

dsnet 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
Copy link
Member Author

dsnet 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
Copy link

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

@gopherbot
Copy link

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
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>
t4n6a1ka pushed a commit to t4n6a1ka/go that referenced this issue Sep 5, 2019
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 golang#18929
Updates golang#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>
@golang golang locked and limited conversation to collaborators Aug 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants