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

go/types, cmd/compile/internal/types2: uninstantiated method in assignment check #46275

Open
findleyr opened this issue May 19, 2021 · 3 comments
Open
Assignees
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented May 19, 2021

Consider the following:

package main

type N[T any] struct {
        *N[T]
        t T
}

func (n *N[T]) Elem() T {
        return n.t
}

type I interface {
        Elem() string
}

func main() {
        var n1 *N[string]
        var _ I = n1
        type NS N[string]
        var n2 *NS
        var _ I = n2
}

This program should type-check cleanly, but does not. The type parameter is unsubstituted in the assignability check: cannot use n2 (variable of type *NS) as I value in variable declaration: wrong type for method Elem (have func() T, want func() string).

CC @griesemer

@findleyr findleyr added this to the Go1.18 milestone May 19, 2021
@findleyr findleyr self-assigned this May 19, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented May 19, 2021

This fails in lookup.go, Checker.missingMethod, in the unify phase around lines 420. There's a TODO, this code may not be correct.

@gopherbot
Copy link

@gopherbot gopherbot commented May 19, 2021

Change https://golang.org/cl/321232 mentions this issue: [dev.typeparams] cmd/compile/internal/types2: use correct type parameter list in missingMethod

gopherbot pushed a commit that referenced this issue May 19, 2021
…ter list in missingMethod

For #46275

Change-Id: Iaed9d8ba034ad793e5c57f2be174f01a535fee95
Reviewed-on: https://go-review.googlesource.com/c/go/+/321232
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 3, 2021

Change https://golang.org/cl/324751 mentions this issue: [dev.typeparams] go/types: use correct type parameter list in missingMethod

gopherbot pushed a commit that referenced this issue Jun 4, 2021
…Method

This is a port of CL 321232 to go/types, adjusted to add a missing
comment and to remove optional support for method type params.

Fixes #46275

Change-Id: I63fcbb669e7607876a888fca89b9064568805448
Reviewed-on: https://go-review.googlesource.com/c/go/+/324751
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
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
3 participants