What version of Go are you using (go version)?
go 1.18beta1
$ go version
go1.18beta1 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/donew/Library/Caches/go-build"
GOENV="/Users/donew/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/donew/src/go/pkg/mod"
GONOPROXY="glab.tagtic.cn"
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/donew/src/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/donew/src/go/go1.18beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/donew/src/go/go1.18beta1/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/donew/Downloads/go118bug/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/92/6vv251ls5_lgh6kmm9xq_wh80000gn/T/go-build1725229051=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
when I was playing with generics I discovered a subtle (possible) compiler bug. go1.18beta1 vet and go1.18beta1 build gives me no complaint but the go1.18beta1 test failed out of no good reason.
The offending code is isolated in https://github.com/Reasno/go1.18beta1bug.
The code with generic:
package bar
type Data[K comparable, V any] struct {
field int
}
type Dataset[K comparable, V any] struct{}
func (m *Dataset[K, V]) GetData() *Data[K, V] {
d := &Data[K, V]{field: 1}
return d
}
var DefaultDataset = Dataset[string, any]{}
func GetData() *Data[string, any] {
return DefaultDataset.GetData()
}
and the test file:
package bar_test
import (
bar "github.com/reasno/go1.18beta1bug"
"testing"
)
func Test(t *testing.T) {
bar.GetData()
}
What did you expect to see?
The go1.18beta1 test compilation should be green.
What did you see instead?
go1.18beta1 test rants: ../main.go:10:24: invalid field name bar.field in struct initializer
What version of Go are you using (
go version)?go 1.18beta1
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env)?go envOutputWhat did you do?
when I was playing with generics I discovered a subtle (possible) compiler bug.
go1.18beta1 vetandgo1.18beta1 buildgives me no complaint but thego1.18beta1 testfailed out of no good reason.The offending code is isolated in https://github.com/Reasno/go1.18beta1bug.
The code with generic:
and the test file:
What did you expect to see?
The
go1.18beta1 testcompilation should be green.What did you see instead?
go1.18beta1 testrants: ../main.go:10:24: invalid field name bar.field in struct initializer