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/types2: Parametrized type method cannot see constraint struct fields #51721

Closed
dtcaciuc opened this issue Mar 16, 2022 · 3 comments
Closed

Comments

@dtcaciuc
Copy link
Contributor

dtcaciuc commented Mar 16, 2022

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

$ go version
go version go1.18 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

The following compiled with go1.18rc1 but not with go1.18 final.

I am not sure if this was supposed to work like that or this was a bug in RC1 that was fixed, but it is useful when Handler is being used as a parameter to another type (say, Scheduler), which needs to call Handler with Work values. EDIT: seeing "has no field or" message tells me that this should be working.

package ticket

import (
        "fmt"
)

type Work struct {
        V int
}

type Handler[T Work] struct {
}

func (h *Handler[T]) Run(work T) {
        fmt.Print(work.V)
}

What did you expect to see?

Successful compilation

$ go version
go version go1.18rc1 linux/amd64
$ go build x.go
$

What did you see instead?

$ go version
go version go1.18 linux/amd64
$ go build x.go
# command-line-arguments
./x.go:15:17: work.V undefined (type T has no field or method V)
$
@findleyr
Copy link
Contributor

See #51576: field access on type parameters was removed for 1.18. It may be added back in a later version of Go.

CC @griesemer -- do we have a tracking issue/proposal for deciding whether to allow this code?

@seankhliao
Copy link
Member

This one? #51259

@findleyr
Copy link
Contributor

#51259 is an even more sophisticated feature, but yes perhaps we can consolidate discussion there.

In any case, closing this as WAI, for now. Please reopen if I'm missing something.

@golang golang locked and limited conversation to collaborators Mar 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants