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: cannot use .this (type *Foo[[]byte]) as type Foo[.shape.[]uint8] in argument #48198

Closed
jfesler opened this issue Sep 5, 2021 · 2 comments

Comments

@jfesler
Copy link

@jfesler jfesler commented Sep 5, 2021

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

% gotip version
go version devel go1.18-9133245 Sat Sep 4 20:35:25 2021 +0000 darwin/arm64

Does this issue reproduce with the latest release?

Latest gotip, yes.

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

go env Output
% gotip env

GO111MODULE="on"
GOARCH="arm64"
GOBIN="/Users/jfesler/bin"
GOCACHE="/Users/jfesler/Library/Caches/go-build"
GOENV="/Users/jfesler/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jfesler/go/pkg/mod"
GONOPROXY="xxxx"
GONOSUMDB="*xxxx"
GOOS="darwin"
GOPATH="/Users/jfesler/go"
GOPRIVATE="xxxx"
GOPROXY="https://xxxx|direct"
GOROOT="/Users/jfesler/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/jfesler/sdk/gotip/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="devel go1.18-9133245 Sat Sep 4 20:35:25 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/05/dq8h20tn4h58j32qn6r75vdc0000gn/T/go-build2830397944=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?


package foo

import (
    "testing"
)

type Foo[T any] struct {
    Generator func() interface{}
}

func NewFoo[T any](template T, generator func() interface{}) Foo[T] {
    return Foo[T]{
        Generator: generator,
    }
}

func (foo Foo[T]) Get() T {
    return foo.Generator().(T)
}

func TestFoo(t *testing.T) {
    _ = NewFoo([]byte{}, func() interface{} {
        return make([]byte, 1)
    })
}

What did you expect to see?

Successful compile.

What did you see instead?


% gotip test
# xxxx/jfesler/uint8-byte-test [xxxx/jfesler/uint8-byte-test.test]
:1: cannot use .this (type *Foo[[]byte]) as type Foo[.shape.[]uint8] in argument to Foo[.shape.[]uint8].Get
@korzhao
Copy link
Contributor

@korzhao korzhao commented Sep 5, 2021

Simple:

package main

type Foo[T any] struct {
}

func (foo Foo[T]) Get()  {
}

func main() {
	_ = Foo[byte]{}
}
package main

type Foo[T any] struct {
}

func (foo Foo[T]) Get()  {
}

func main() {
	_ = Foo[[]byte]{}
}
package main

type Foo[T any] struct {
}

func (foo Foo[T]) Get()  {
}

func main() {
	_ = Foo[map[byte]byte]{}
}

Loading

@seankhliao seankhliao changed the title generics: cannot use .this (type *Foo[[]byte]) as type Foo[.shape.[]uint8] in argument cmd/compile: cannot use .this (type *Foo[[]byte]) as type Foo[.shape.[]uint8] in argument Sep 6, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 6, 2021

Change https://golang.org/cl/347491 mentions this issue: cmd/compile: make sure that the names created for instantiated type are the same

Loading

@gopherbot gopherbot closed this in 6226020 Sep 7, 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
4 participants