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

cmd/go2go: inferring an unimported type results in confusing error #39625

benjaminjkraft opened this issue Jun 16, 2020 · 3 comments
Assignees
Labels
Milestone

Comments

@benjaminjkraft
Copy link

@benjaminjkraft benjaminjkraft commented Jun 16, 2020

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

@ianlancetaylor ianlancetaylor commented Jun 17, 2020

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

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jun 17, 2020
@ianlancetaylor ianlancetaylor self-assigned this Jun 17, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 18, 2020

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

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 18, 2020

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
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.