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: incorrect "cannot use .this" error when using _ for multiple type parameters in method declaration #50419

Open
samherrmann opened this issue Jan 4, 2022 · 3 comments
Assignees
Milestone

Comments

@samherrmann
Copy link

@samherrmann samherrmann commented Jan 4, 2022

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

$ go version
go version go1.18beta1 linux/amd64

Does this issue reproduce with the latest release?

N/A. Type parameters are not available in any other version that are currently available.

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

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOVERSION="go1.18beta1"

What did you do?

package main

import (
    "fmt"
)

func main() {
    foo := &Foo[string, int]{
        valueA: "i am a string",
        valueB: 123,
    }
    fmt.Println(foo)
}

type Foo[T1 any, T2 any] struct {
    valueA T1
    valueB T2
}

func (f *Foo[_,_]) String() string {
    return fmt.Sprintf("%v %v", f.valueA, f.valueB)
}

What did you expect to see?

I expected the code snippet above to build and run successfully.

What did you see instead?

Build error:

<autogenerated>:1: cannot use .this (type *Foo[string,int]) as type *Foo[go.shape.string_0,go.shape.string_0] in argument to (*Foo[go.shape.string_0,go.shape.int_1]).String
@danscales
Copy link

@danscales danscales commented Jan 4, 2022

Thanks for the issue report!

This is a problem in the main compiler (not the types2 typechecker). It happens when generating method wrappers. It looks like the use of [_, _] in func (f *Foo[_, _]) String() string { is causing the bug - we are somehow interpreting the blanks as the same type. Works fine if you just replace [_, _] with [T1, T2].

@danscales danscales changed the title build: Cannot use .this error when using _ for multiple type parameters in method declaration cmd/compile: incorrect "cannot use .this" error when using _ for multiple type parameters in method declaration Jan 4, 2022
@danscales danscales self-assigned this Jan 4, 2022
@danscales danscales added this to the Go1.18 milestone Jan 4, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 4, 2022

Change https://golang.org/cl/375474 mentions this issue: cmd/compile: make sure multiple blanks typeparams are still unique

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 5, 2022

Change https://golang.org/cl/375641 mentions this issue: go/internal/gcimporter: don't add blank type parameters to tparamIndex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants