Compiler can't apply type parameters to embed type in compisite literals.
What version of Go are you using (go version)?
$ go version
go version devel go1.19-9956a5423e Thu Mar 17 03:41:50 2022 +0000 windows/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
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\mattn\AppData\Local\go-build
set GOENV=C:\Users\mattn\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\mattn\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\mattn\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\dev\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\dev\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.19-9956a5423e Thu Mar 17 03:41:50 2022 +0000
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\mattn\go\src\github.com\mattn\go-tensorflow-realtime-object-detection\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\mattn\AppData\Local\Temp\go-build1850869103=/tmp/go-build -gno-record-gcc-switches
What did you do?
package main
import (
"fmt"
)
type Based[B any] struct {
v1 B
}
type Derived[T, B any] struct {
Based[B]
v2 T
}
func main() {
v := Derived[string, int]{
Based: Based[int]{
v1: 1,
},
v2: "abc",
}
fmt.Println(v.v1, v.v2)
}
https://play.golang.com/p/LXEpnd3fxBm
What did you expect to see?
It is possible to omit [int] for inner literal.
package main
import (
"fmt"
)
type Based[B any] struct {
v1 B
}
type Derived[T, B any] struct {
Based[B]
v2 T
}
func main() {
v := Derived[string, int]{
Based: Based {
v1: 1,
},
v2: "abc",
}
fmt.Println(v.v1, v.v2)
}
What did you see instead?
./prog.go:18:10: cannot use generic type Based[B any] without instantiation
https://play.golang.com/p/AwgNEDDi7zT
If compile without type parameters, it pass to compile.
https://play.golang.com/p/8J8FAusLKe2
Compiler can't apply type parameters to embed type in compisite literals.
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env)?go envOutputWhat did you do?
https://play.golang.com/p/LXEpnd3fxBm
What did you expect to see?
It is possible to omit
[int]for inner literal.What did you see instead?
https://play.golang.com/p/AwgNEDDi7zT
If compile without type parameters, it pass to compile.
https://play.golang.com/p/8J8FAusLKe2