Closed
Description
What version of Go are you using (go version
)?
1.18beta1
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/home/thomascoquet/.cache/go-build" GOENV="/home/thomascoquet/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/thomascoquet/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/thomascoquet/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/thomascoquet/sdk/go1.18beta1" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/thomascoquet/sdk/go1.18beta1/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18beta1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/thomascoquet/Work/gobug/go.mod" 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-build724234361=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I am using a generic interface the following way:
package gogenerics
import "fmt"
type Float interface {
float32 | float64
}
type Doer[T Float] interface {
Do() T
}
func Specialize[T Float](v Doer[T]) {
switch v.(type) {
case Doer[float32]:
fmt.Println("float32!")
case Doer[float64]:
fmt.Println("float64!")
}
}
What did you expect to see?
No error message.
What did you see instead?
When building or using go test ./...
, I have the following message:
impossible type assertion: no type can implement both gogenerics.Doer[T] and gogenerics.Doer[float32] (conflicting types for Do method)
The error message also appears in VSCode (with the syntax highlighter using gopls with generics enabled).
I must emphasize that this code works perfectly well if imported from other modules ; the only isssue is when using the module "from itself".