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/go2go: instantiating struct w/ generic embedded member fails #39671

Closed
shanemhansen opened this issue Jun 17, 2020 · 4 comments
Closed

cmd/go2go: instantiating struct w/ generic embedded member fails #39671

shanemhansen opened this issue Jun 17, 2020 · 4 comments

Comments

@shanemhansen
Copy link
Contributor

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?

# play
./prog.go2:16: undefined: T
@shanemhansen
Copy link
Contributor Author

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

@shanemhansen
Copy link
Contributor Author

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
}

@gopherbot
Copy link

Change https://golang.org/cl/238621 mentions this issue: [dev.go2go] go/go2go: instantiate embedded type parameters

@ianlancetaylor
Copy link
Contributor

Thanks, this should be fixed now.

gopherbot pushed a commit that referenced this issue Jun 17, 2020
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>
@golang golang locked and limited conversation to collaborators Jun 17, 2021
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

3 participants