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

cmd/compile: invalid field name *** in struct initializer #50848

Closed
Reasno opened this issue Jan 27, 2022 · 5 comments
Closed

cmd/compile: invalid field name *** in struct initializer #50848

Reasno opened this issue Jan 27, 2022 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Reasno
Copy link

Reasno commented Jan 27, 2022

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

@randall77
Copy link
Contributor

This seems to be fixed at tip. Can you try that to verify, or we should have beta2 out in a few days which should also have this fixed.

@mknyszek mknyszek added this to the Go1.18 milestone Jan 27, 2022
@mknyszek mknyszek added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 27, 2022
@mknyszek
Copy link
Contributor

Because this seems to be fixed, not marking as a release blocker. Waiting for info from OP to verify that it's fixed at tip.

@mknyszek mknyszek added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 27, 2022
@Reasno
Copy link
Author

Reasno commented Jan 28, 2022

I compiled go from git master and the issue remains

$ go version
go version devel go1.18-9ff0039848 Fri Jan 28 02:40:34 2022 +0000 darwin/amd64
$ go test
# github.com/reasno/go1.18beta1bug_test [github.com/reasno/go1.18beta1bug.test]
./main.go:10:24: invalid field name bar.field in struct initializer
FAIL    github.com/reasno/go1.18beta1bug [build failed]

@randall77
Copy link
Contributor

I can't get it to fail at tip (@9ff00398489d9eb1822b3de028cd6ccf5674ebb3) but I can at 1.18beta1.

Just to be clear I have a directory issue50848 with three items in it:

go.mod:

module issue50848

go 1.18

issue50848_test.go:

package issue50848_test

import (
	"testing"

	"issue50848/bar"
)

func Test(t *testing.T) {
	bar.GetData()
}

and a directory bar with one file in it, bar.go:

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()
}

Which gives:

issue50848 % ~/go1.18beta1/bin/go test
# issue50848_test [issue50848.test]
./bar/bar.go:10:24: invalid field name bar.field in struct initializer
FAIL	issue50848 [build failed]
issue50848 % ~/sandbox/ro/bin/go test 
PASS
ok  	issue50848	0.004s

(~/sandbox/ro is synced and make.bash'd at the commit listed above.)

@Reasno
Copy link
Author

Reasno commented Jan 28, 2022

go version devel go1.18-9ff0039848 Fri Jan 28 02:40:34 2022 +0000 darwin/amd64

Looks like you are right.

My IDE has GOROOT="~/src/go/go1.18beta1"set even though the binary I used is the latest. In a fresh terminal, I can confirm the bug is fixed at tip.

Thanks for the hard work.

@golang golang locked and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants