Closed
Description
What version of Go are you using (go version
)?
$ go version 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="~/Library/Caches/go-build" GOENV="~/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="~/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="~/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="~/sdk/go1.18beta1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="~/sdk/go1.18beta1/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.18beta1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD= 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/m4/5y8kv34x7hn27crxq3cgwmrh0000gn/T/go-build3708845374=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
type CanQuack[Q any] interface {
Quack() Q
}
type Duck[Q any] struct {
quack Q
}
func (d Duck[Q]) Quack() Q {
return d.quack
}
func ForceQuack[Q any](quacker CanQuack[Q]) {
print(quacker.Quack())
}
func main() {
duck := Duck[string]{quack: "great success"} // redundant type specification forced by #50482
ForceQuack(duck) // still, compiler cannot infer Q
}
What did you expect to see?
great success
What did you see instead?
type Duck[string] of duck does not match CanQuack[Q] (cannot infer Q)