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: inferring an unimported type results in confusing error #39625

Closed
benjaminjkraft opened this issue Jun 16, 2020 · 3 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@benjaminjkraft
Copy link

Consider the following code (playground):

package main

import (
	"io/ioutil"
)

func F(type T, U)(func(T) (U, error)) {}

func main() {
	F(ioutil.ReadAll) // F(io.Reader, []byte)(ioutil.ReadAll)
}

Note that in the call to F, the type parameter T ends up being inferred as io.Reader, which is not explicitly imported (although of course it is transitively). This results in the following confusing errors:

./prog.go2:9: cannot use ioutil.ReadAll (type func(io.Reader) ([]byte, error)) as type func(<T>) ([]byte, error) in argument to instantiate୦୦F୦io୮aReader୦୮6୮7byte
./prog.go2:7: undefined: io in io.Reader

Adding a blank import _ "io" works around the problem; presumably this shouldn't be necessary.

@ianlancetaylor
Copy link
Contributor

Interesting. This is a bug in the translation tool. Thanks for reporting it.

@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 17, 2020
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 17, 2020
@ianlancetaylor ianlancetaylor self-assigned this Jun 17, 2020
@ianlancetaylor
Copy link
Contributor

Thanks. This is now fixed in the dev.go2go branch.

@gopherbot
Copy link

Change https://golang.org/cl/238817 mentions this issue: [dev.go2go] go/go2go: add imports for packages referenced by inferred types

gopherbot pushed a commit that referenced this issue Jun 18, 2020
… types

Fixes #39625

Change-Id: Iebae2afbb42092e14c91c52d2046bc287d423844
Reviewed-on: https://go-review.googlesource.com/c/go/+/238817
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@golang golang locked and limited conversation to collaborators Jun 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants