-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
What version of Go are you using (go version
)?
$ go version go version go1.17rc1 linux/amd64
Does this issue reproduce with the latest release?
It reproduces with go1.17rc1 but not go1.16
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/zyedidia/.cache/go-build" GOENV="/home/zyedidia/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/zyedidia/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/zyedidia/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/zyedidia/sdk/go1.17rc1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/zyedidia/sdk/go1.17rc1/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17rc1" GCCGO="/usr/bin/gccgo" AR="ar" CC="gcc" CXX="g++" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3213770622=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I created two files: test1.go
and test2.go
:
test1.go
:
package main
import (
. "fmt"
)
func test() {
Println("foo")
}
test2.go
:
package main
func Println() {}
func main() {}
Then I ran go1.17rc1 build
. The names of the files are important for ordering.
What did you expect to see?
I expect to see an error telling me that a function from a dot-imported package collides with a function defined in the file, or maybe no error (this is the behavior of Go 1.16, but this also seems wrong). If alphabetical ordering of the files is swapped (by renaming test2.go
to test0.go
), I observe the correct behavior: Go 1.16 reports a number of errors, and Go 1.17rc1 reports the same ones:
./test1.go:4:2: Println redeclared during import "fmt"
previous declaration at ./test0.go:3:6
./test1.go:4:2: imported and not used: "fmt"
./test1.go:8:9: too many arguments in call to Println
have (string)
want ()
What did you see instead?
However with the ordering from the original description above, Go 1.16 reports no issues (and successfully generates a binary) and Go 1.17rc1 fails with a panic:
panic: interface conversion: types.Object is nil, not *ir.Ident
goroutine 1 [running]:
cmd/compile/internal/typecheck.Redeclared({0x50, 0x0}, 0xc000419db0, {0xcec6ae, 0xd})
/usr/local/go/src/cmd/compile/internal/typecheck/dcl.go:109 +0x2c5
cmd/compile/internal/typecheck.Declare(0xc00042aea0, 0x7)
/usr/local/go/src/cmd/compile/internal/typecheck/dcl.go:77 +0x4d2
cmd/compile/internal/noder.(*noder).funcDecl(0xc0003ccc40, 0xc00040e060)
/usr/local/go/src/cmd/compile/internal/noder/noder.go:584 +0x585
cmd/compile/internal/noder.(*noder).decls(0xc0003ccc40, {0xc00041c0a0, 0x2, 0xc0004100c0})
/usr/local/go/src/cmd/compile/internal/noder/noder.go:331 +0x2c5
cmd/compile/internal/noder.(*noder).node(0xc0003ccc40)
/usr/local/go/src/cmd/compile/internal/noder/noder.go:285 +0xb8
cmd/compile/internal/noder.LoadPackage({0xc00001e250, 0x3, 0x0})
/usr/local/go/src/cmd/compile/internal/noder/noder.go:85 +0x358
cmd/compile/internal/gc.Main(0xd16418)
/usr/local/go/src/cmd/compile/internal/gc/main.go:192 +0xb2e
main.main()
/usr/local/go/src/cmd/compile/main.go:55 +0xdd
Go vet catches the error in both file orderings.