-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.TypeInferenceIssue is related to generic type inferenceIssue is related to generic type inferencegenericsIssue is related to genericsIssue is related to generics
Milestone
Description
What version of Go are you using (go version)?
$ go version go version devel go1.18-87b2a548 Sun Dec 19 20:16:45 2021 +0000 linux/amd64
Does this issue reproduce with the latest release?
No, generics are required
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/vlad/.cache/go-build" GOENV="/home/vlad/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/vlad/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/vlad/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/vlad/sdk/gotip" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/vlad/sdk/gotip/pkg/tool/linux_amd64" GOVCS="" GOVERSION="devel go1.18-87b2a548 Sun Dec 19 20:16:45 2021 +0000" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3350654881=/tmp/go-build -gno-record-gcc-switches"
What did you do?
Compile this code:
func a[T any, S []T](s S) int {
return b(s)
}
func b[T any](s []T) int {
return len(s)
}
func main() {
a(make([]int, 0))
}What did you expect to see?
The code should compile successfully
What did you see instead?
Compilation failed with type S of s does not match []T (cannot infer T) error message
This code compiles fine:
func a[T any, S []T](s S) int {
return b([]T(s))
}
func b[T any](s []T) int {
return len(s)
}
func main() {
a(make([]int, 0))
}Reactions are currently unavailable
Metadata
Metadata
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.TypeInferenceIssue is related to generic type inferenceIssue is related to generic type inferencegenericsIssue is related to genericsIssue is related to generics
Type
Projects
Status
Done