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: confusing error in type inference #48196

Closed
reusee opened this issue Sep 5, 2021 · 1 comment
Closed

cmd/compile: confusing error in type inference #48196

reusee opened this issue Sep 5, 2021 · 1 comment

Comments

@reusee
Copy link

@reusee reusee commented Sep 5, 2021

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

$ go version
go version devel go1.18-9133245be7 Sat Sep 4 20:35:25 2021 +0000 windows/amd64

Does this issue reproduce with the latest release?

No

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

go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\reus\AppData\Local\go-build
set GOENV=C:\Users\reus\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=unified
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\reus\go\pkg\mod
set GONOPROXY=github.com/reusee/*
set GONOSUMDB=github.com/reusee/*
set GOOS=windows
set GOPATH=C:\Users\reus\go
set GOPRIVATE=github.com/reusee/*
set GOPROXY=https://goproxy.cn,direct
set GOROOT=C:\Users\reus\gotip
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\reus\gotip\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.18-9133245be7 Sat Sep 4 20:35:25 2021 +0000
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
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\reus\AppData\Local\Temp\go-build3421342756=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version devel go1.18-9133245be7 Sat Sep 4 20:35:25 2021 +0000 windows/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.18-9133245be7 Sat Sep 4 20:35:25 2021 +0000 X:unified

What did you do?

package main

type IntSink func(*int) IntSink

func Discard[
        T any,
        Sink interface {
                ~func(*T) Sink
        },
](v *T) Sink {
        return Discard[T, Sink]
}

func Copy[
        T any,
        Sink interface {
                ~func(*T) Sink
        },
](sink Sink) {
}

func main() {
        // no error
        Copy[int, IntSink](
                Discard[int, IntSink],
        )

        // func(v *int) IntSink does not satisfy interface{~func(*T) Sink}
        Copy[int](
                Discard[int, IntSink],
        )
}

What did you expect to see?

IntSink satisfies Sink if explicitly supplied.
Should not report that it doesn't satisfy when infer.

What did you see instead?

# command-line-arguments
.\a.go:29:11: func(v *int) IntSink does not satisfy interface{~func(*T) Sink}
@ALTree ALTree added this to the Go1.18 milestone Sep 6, 2021
@reusee
Copy link
Author

@reusee reusee commented Sep 10, 2021

I think I understand why the type matching failed now. To implement the recursive Sink interface, the argument type must be a recursive named type. But the inference produces the unnamed func(v *int) IntSink which does not implement Sink, although it's the underlying type of the named IntSink.

Close the issue since it's working as expected.

Loading

@reusee reusee closed this Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants