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: any input to format.Source panics #42300

Closed
FiloSottile opened this issue Oct 30, 2020 · 3 comments
Closed

go/format: any input to format.Source panics #42300

FiloSottile opened this issue Oct 30, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@FiloSottile
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version devel +91b7619310 Thu Oct 22 15:30:02 2020 +0000 darwin/amd64

Does this issue reproduce with the latest release?

It does not reproduce with Go 1.15.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/valsorda/Library/Caches/go-build"
GOENV="/Users/valsorda/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/valsorda/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/valsorda"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/valsorda/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/valsorda/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/df/mrk3bfz149n8zb5h5p1vp_1m00hbbm/T/go-build525898641=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Pass any input to format.Source.

https://play.golang.org/p/kZcA7s59sam

What did you expect to see?

Formatted output.

What did you see instead?

panic: unreachable

goroutine 1 [running]:
go/printer.(*printer).expr1(0xc000167ab0, 0x29712dc0, 0xc0004f6100, 0x0, 0x1)
	/Users/valsorda/go/src/go/printer/nodes.go:973 +0x274e
go/printer.(*printer).expr(...)
	/Users/valsorda/go/src/go/printer/nodes.go:1067
go/printer.(*printer).printNode(0xc000167ab0, 0x12bb140, 0xc0004f6100, 0xc00037a170, 0x100fe78)
	/Users/valsorda/go/src/go/printer/printer.go:1128 +0x385
go/printer.(*Config).fprint(0xc000167d20, 0x1363640, 0xc0001ba3c0, 0xc0002e6000, 0x12bb140, 0xc0004f6100, 0xc0001ba3f0, 0xc0002e6000, 0x0)
	/Users/valsorda/go/src/go/printer/printer.go:1309 +0x170
go/printer.(*Config).Fprint(...)
	/Users/valsorda/go/src/go/printer/printer.go:1367
go/format.format(0xc0002e6000, 0xc0004f6100, 0x0, 0x0, 0xc000828000, 0x49d49, 0x92e01, 0x40000006, 0x8, 0x0, ...)
	/Users/valsorda/go/src/go/format/internal.go:105 +0x671
go/format.Source(0xc000828000, 0x49d49, 0x92e01, 0x1, 0x0, 0x0, 0x0, 0x1)
	/Users/valsorda/go/src/go/format/format.go:116 +0x127

panic("unreachable")

This is reached because the type of expr is *ast.File, which is not handled by the type switch.

@FiloSottile FiloSottile added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Oct 30, 2020
@FiloSottile FiloSottile added this to the Go1.16 milestone Oct 30, 2020
@ianlancetaylor
Copy link
Contributor

I can't reproduce this.

@ianlancetaylor
Copy link
Contributor

The type *ast.File does not implement the interface ast.Expr, so the code should never get to the point of the panic (and, for me, it doesn't).

@FiloSottile
Copy link
Contributor Author

Indeed, neither does it for me after trying to bisect it. I suppose I was using a cmd/go out of sync with the Go tree and weird things were happening. I do wish there some level of safety against that. make.bash is fast but not so fast I run it on every git checkout, and I never know if I skipped over some change that will cause random compiler behaviors.

@golang golang locked and limited conversation to collaborators Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants