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: did not infer implementation[actual] passed to interface[generic] #56294

Closed
vahid-sohrabloo opened this issue Oct 18, 2022 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. TypeInference Issue is related to generic type inference
Milestone

Comments

@vahid-sohrabloo
Copy link

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

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

Yes. it does

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vahid/.cache/go-build"
GOENV="/home/vahid/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vahid/go/pkg/mod"
GONOPROXY="github.com/dolphinfms/*"
GONOSUMDB="github.com/dolphinfms/*"
GOOS="linux"
GOPATH="/home/vahid/go/"
GOPRIVATE="github.com/dolphinfms/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4148583324=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://go.dev/play/p/iTbFKExhVeZ

What did you expect to see?

B(&Imp[int64]{}) doesn't work and show cannot infer T error but B[int64](&Imp[int64]{}) works. But it can auto infer. in this example, the T of B is always int64

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 18, 2022
@dr2chase dr2chase changed the title affected/package: cmd/compile: did not infer implementation[actual] passed to interface[generic] Oct 18, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Oct 18, 2022
@dr2chase
Copy link
Contributor

I think this is working-as-intended -- not everything that could be inferred, is inferred.

@griesemer or @mdempsky would know better.

@mdempsky
Copy link
Contributor

/cc @findleyr @ianlancetaylor

@ianlancetaylor
Copy link
Contributor

The compiler is correct according to the current type inference rules. There is no type inference from the type of an argument to the instantiation of a generic type used as an ordinary parameter.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 19, 2022
@ianlancetaylor ianlancetaylor added generics Issue is related to generics TypeInference Issue is related to generic type inference labels Oct 19, 2022
@vahid-sohrabloo
Copy link
Author

should we change the rules? it doesn't make sense to infer it. it only can be int64

@dr2chase
Copy link
Contributor

My understanding of The Plan is that we want to let the current rules soak for a while, and see how things work as they are. Once we extend an inference rule, we can't retract it, and there might be impacts on other parts of type inference, analysis time, other tools, error message quality, and perhaps readability (which is more important than write-ability). We're still dealing with some of the long-tail problems of the generics addition (build speed, IR changes, export data changes, deciding how we feel about cyclic interfaces, and "comparable").

Anyhow, I'll close with working-as-intended-for-now. We ought to revisit this in a year or so.

@griesemer
Copy link
Contributor

Update: This works now on the dev branch (eventual Go 1.21).

@golang golang locked and limited conversation to collaborators May 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. TypeInference Issue is related to generic type inference
Projects
None yet
Development

No branches or pull requests

6 participants