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: Translation fails when inferring a aliased generic type #39797
Comments
The following fails with the same translator error: package i2
import "./a"
type S = a.S
type T(type A, B) func(A) B
func F1(type T)(t T) { }
func (tr T(A, B)) M() { F1(*new(B)) }
func F2() { _ = T(string, S(string))(nil) } |
What are your This is what happens for me.
|
|
Change https://golang.org/cl/239703 mentions this issue: |
I've committed a patch to the dev.go2go branch that affects how dot imports are handled. But I don't know whether it fixes your test case. |
For #39797 Change-Id: I4063a0138062ce8dc1f35cc7fef7c6773c939362 Reviewed-on: https://go-review.googlesource.com/c/go/+/239703 Reviewed-by: Ian Lance Taylor <iant@golang.org>
OK, thanks. I'll leave this open but I don't plan to fix it. My main interest for the go2go tool to support |
That's what's weird, I'm not using relative imports. I put `import "./a" in the example above to simplify it, but if you look at gitlab.com/firelizzard/go-iter/i2/i2.go2, the import is absolute. Somewhere in the translation, |
Change https://golang.org/cl/239707 mentions this issue: |
OK, I think I see. Because the file imports a gitlab.com path, this has to be under $GO2PATH/src/gitlab.com/firelizzard/go-iter. I just committed a fix that makes that case work for me. Closing, but let me know if you still have trouble. |
No test because it doesn't really fit into the current test harness. FIxes #39797 Change-Id: I410217a0e6b3af6808a111d0edbafaa3047b12f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/239707 Reviewed-by: Ian Lance Taylor <iant@golang.org>
That works, thanks! |
If
package a
definestype S
as a generic type,package b
definestype S = b.S
, if a expression of typeS
is passed to a generic function without specifying the function's type parameters (relying on inference),go tool go2go build
will fail in a peculiar way. It does not fail if the type parameter is passed explicitly.Replacing
return err
withpanic(err)
on rewrite.go:361 inrewriteAST
produces the following:During
*translator.translate
,*translator.addTypePackages
addstyp.Obj().Pkg()
tot.typePackages
, which is to generate a list of import statements. Becausetyp.Obj().Pkg().Path()
only includes the package name ("a") and not the full path, the generated import statement is justimport "a"
, and that causes problems. This can eventually be traced back to the fact thatgo/go2go.parseFiles
uses thepackage <name>
as the package path instead of a full path.What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
git clone https://gitlab.com/firelizzard/go-iter
cd go-iter/issues/i2
go tool go2go build
What did you expect to see?
A successful build
What did you see instead?
The text was updated successfully, but these errors were encountered: