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: embedding doesn't seem to work? #39881

Closed
lavalamp opened this issue Jun 26, 2020 · 3 comments
Closed

cmd/go2go: embedding doesn't seem to work? #39881

lavalamp opened this issue Jun 26, 2020 · 3 comments

Comments

@lavalamp
Copy link

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

$ go version
go version devel +1b08acee45 Thu Jun 25 23:22:18 2020 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes, as of commit 1b08ace

What did you do?

$ go tool go2go run err.go2 
# command-line-arguments
./err.go2:8: undefined: embedPair
./err.go2:8: type a is not an expression
./err.go2:8: type b is not an expression

where err.go2 is:

package main

type a struct{}
type b struct{}
type c struct{}

type embedPair(type T, U) struct {
        T
        U
}

func main() {
        _ = embedPair(embedPair(a, b), c){}
}

It gives a different error in the playground: https://go2goplay.golang.org/p/2h7HWFVkvW2

(a couple days ago it crashed, so this is better than it was)

What did you expect to see?

I expected it to construct a type like:

type x struct {
  a
  b
}

type y struct {
  x
  c
}

Only x will be unnamed, so I'm not sure how this is supposed to work, which is why I was trying it.

What did you see instead?

It gives confusing error messages.

@dpinela
Copy link
Contributor

dpinela commented Jun 26, 2020

I am running into (possibly) the same problem (this is simplified from a more complicated function):

package main

func P(type T, U)(x T, y U) struct {
	T
	U
} {
	return struct {
		T
		U
	}{x, y}
}

func main() {
	_ = P(5, "apples")
}

@ianlancetaylor
Copy link
Contributor

Thanks. These test cases should now be fixed on the dev.go2go branch.

@gopherbot
Copy link

Change https://golang.org/cl/240197 mentions this issue: [dev.go2go] go/go2go: translate types to AST

gopherbot pushed a commit that referenced this issue Jun 26, 2020
We were relying on calling typeString and treating that as an AST ident,
with special handling for instantiated types, but that fails if there is
an instantiated type within a type literal.

Fixes #39881

Change-Id: I793fe359868d8d73e830aa8dc67cf52de99355a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/240197
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Jun 26, 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

4 participants