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

Closed
DeedleFake opened this issue Jun 21, 2020 · 3 comments
Closed

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

DeedleFake opened this issue Jun 21, 2020 · 3 comments

Comments

@DeedleFake
Copy link

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.

Playground

package main

import (
	"encoding/json"
	"fmt"
	"io"
	"strings"
)

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 {
		panic(err)
	}
	fmt.Printf("%#v", t)
}

Output:

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

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.

@gopherbot
Copy link

Change https://golang.org/cl/239380 mentions this issue: [dev.go2go] go/go2go: check for instantiation with locally defined type

@ianlancetaylor
Copy link
Contributor

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