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

types2, go/types: "cannot convert to type" regression with alias to pointer types #67540

Closed
mvdan opened this issue May 21, 2024 · 6 comments
Closed
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.

Comments

@mvdan
Copy link
Member

mvdan commented May 21, 2024

Go version

go version devel go1.23-22344e11f2 2024-05-20 21:19:39 +0000 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/mvdan/.cache/go-build'
GOENV='/home/mvdan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/mvdan/go/pkg/mod'
GONOPROXY='github.com/cue-unity'
GONOSUMDB='github.com/cue-unity'
GOOS='linux'
GOPATH='/home/mvdan/go'
GOPRIVATE='github.com/cue-unity'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/mvdan/tip'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/mvdan/tip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.23-22344e11f2 2024-05-20 21:19:39 +0000'
GODEBUG=''
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/mvdan/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3927267404=/tmp/go-build -gno-record-gcc-switches'

What did you do?

$ git clone https://github.com/ipld/go-codec-dagpb
$ cd go-codec-dagpb
$ go build

What did you see happen?

$ go version
go version devel go1.23-22344e11f2 2024-05-20 21:19:39 +0000 linux/amd64
$ go build
# github.com/ipld/go-codec-dagpb
./ipldsch_satisfaction.go:1164:26: cannot convert n (variable of type PBLink) to type *_PBLink__Repr
./ipldsch_satisfaction.go:2010:27: cannot convert n (variable of type PBLinks) to type *_PBLinks__Repr
./ipldsch_satisfaction.go:2024:22: cannot convert nr (variable of type *_PBLinks__Repr) to type PBLinks
./ipldsch_satisfaction.go:2031:22: cannot convert nr (variable of type *_PBLinks__Repr) to type PBLinks
./ipldsch_satisfaction.go:2048:42: cannot convert nr (variable of type *_PBLinks__Repr) to type PBLinks
./ipldsch_satisfaction.go:2754:26: cannot convert n (variable of type PBNode) to type *_PBNode__Repr

What did you expect to see?

No error, just like previous versions of Go:

$ go version
go version go1.22.3 linux/amd64
$ go build
$ echo $?
0
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/587075 mentions this issue: types2, go/types: fix pointer types check during typecheck conversions

@cuonglm
Copy link
Member

cuonglm commented May 21, 2024

This is an issue with types2 (and go/types), not the cmd/go.

Minimal reproducer:

package p

type _s struct{}
type s = *_s

type _s_repr _s

func (n s) M() any {
	return (*_s_repr)(n)
}

@cuonglm cuonglm changed the title cmd/go: "cannot convert to type" regression in tip with type conversions types2, go/types: "cannot convert to type" regression in tip with type conversions May 21, 2024
@cuonglm cuonglm changed the title types2, go/types: "cannot convert to type" regression in tip with type conversions types2, go/types: "cannot convert to type" regression with alias to pointer types May 21, 2024
@cuonglm cuonglm added NeedsFix The path to resolution is known, but the work has not been done. compiler/runtime Issues related to the Go compiler and/or runtime. labels May 21, 2024
@cuonglm cuonglm self-assigned this May 21, 2024
@mvdan
Copy link
Member Author

mvdan commented May 21, 2024

This is an issue with types2 (and go/types), not the cmd/go.

I'm not familiar with compiler internals, so I just file the issue with a generic title first :)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/587156 mentions this issue: go/types, types2: add missing Unalias calls (clarification)

gopherbot pushed a commit that referenced this issue May 21, 2024
This change adds an Unalias call in applyTypeFunc and arrayPtrDeref.
At the moment this doesn't change anything or fix any bugs because
of the way these two functions are invoked, but that could change
in the future.

Also, manually reviewed all type assertions to Type types.

Excluding assertions to type parameters, no obvious issues
were found except for #67540 for which a separate fix is pending.

There are potential issues with assertions type parameters
which will be addressed in a follow-up CL.

For #67547.

Change-Id: I312268dc5e104f95b68f115f00aec3ec4c82e41f
Reviewed-on: https://go-review.googlesource.com/c/go/+/587156
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/587159 mentions this issue: go/types, types2: operand.convertibleTo must consider alias types

@mvdan
Copy link
Member Author

mvdan commented May 23, 2024

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants