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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@jfesler
Copy link

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 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]{}
}

@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
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 6, 2021
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants