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/go2go: instantiating struct w/ generic embedded member fails #39671
Comments
Notice that the types/methods will compile, the error only occurs when they are used. The following code from the draft spec compiles: https://go2goplay.golang.org/p/xPQmnRMC2kV |
Downloaded go2go and examined the generated source. It appears that embedded generic types are left alone during instantiation, but post instantiation the generic "T" type is no longer defined. Generated incorrect code: //line main.go2:7
type instantiate୦୦Lockable୦string struct {
//line main.go2:11
T
mu sync.Mutex
} Correct code (I think) with T replaced with the instantiated type: //line main.go2:7
type instantiate୦୦Lockable୦string struct {
//line main.go2:11
T string
mu sync.Mutex
} |
Change https://golang.org/cl/238621 mentions this issue: |
Thanks, this should be fixed now. |
Turn an embedded type parameter into a regular field with the type parameter as the name and the type argument as the type. Fixes #39671 Change-Id: I0050499b90feb5085cac4452d53fa0dc6f614c48 Reviewed-on: https://go-review.googlesource.com/c/go/+/238621 Reviewed-by: Ian Lance Taylor <iant@golang.org>
What version of Go are you using (
go version
)?Go2go playground: https://go2goplay.golang.org/p/xwo0nvioxDT
Does this issue reproduce with the latest release?
Yes
What did you do?
Used the lock type mentioned in the generics draft.
https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md
https://go2goplay.golang.org/p/xwo0nvioxDT
It appears that when you use generic struct embedding AND attempt to instantiate the generic struct you get an error: "undefined: T"
What did you expect to see?
I expected the program to compile.
What did you see instead?
The text was updated successfully, but these errors were encountered: