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: local type as type parameter fails #39738

DeedleFake opened this issue Jun 21, 2020 · 3 comments

cmd/go2go: local type as type parameter fails #39738

DeedleFake opened this issue Jun 21, 2020 · 3 comments


Copy link

@DeedleFake DeedleFake commented Jun 21, 2020

This makes sense given the way that go2go works, but it should probably at least give a clearer error message that explains that the tool doesn't support that.


package main

import (

func Decode(type T)(r io.Reader) (T, error) {
	var t T
	err := json.NewDecoder(r).Decode(&t)
	return t, err

func main() {
	type s struct {
		This string `json:"this"`
		A    string `json:"a"`

	t, err := Decode(s)(strings.NewReader(`{"this": "is", "a": "test"}`))
	if err != nil {
	fmt.Printf("%#v", t)


# play
./prog.go2:22: undefined: s
./prog.go2:11: undefined: s
Copy link

@DeedleFake DeedleFake commented Jun 21, 2020

This seems to be a duplicate of #39643, but while it's not panicking it's not giving the new error message, either. It's a similar case but not quite the same.

Copy link

@gopherbot gopherbot commented Jun 22, 2020

Change mentions this issue: [dev.go2go] go/go2go: check for instantiation with locally defined type

Copy link

@ianlancetaylor ianlancetaylor commented Jun 22, 2020

Thanks. This is now fixed on the dev.go2go branch, in that the go2go tool will give a better error message:

foo.go2:22:19: go2go tool does not support using locally defined type as type argument
gopherbot pushed a commit that referenced this issue Jun 22, 2020
Fixes #39738

Change-Id: I1a3536484a982ec713019572ff7b3c0c36af9784
Reviewed-by: Ian Lance Taylor <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.