You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If package x contains a type X that is a parameterized type, and package y contains a type Y = x.X, go tool go2go build will fail with a panic upon attempting to instantiate type Y.
This fails because spec *ast.TypeSpec for an alias has spec.TParams == nil, which causes a panic in *translator.instantiateTypeDecl. A workaround is to modify *translator.findTypeSpec to resolve type aliases to the *ast.TypeSpec of the underlying type:
diff --git a/src/go/go2go/instantiate.go b/src/go/go2go/instantiate.go
index bcb38de64a..2351ee6c13 100644
--- a/src/go/go2go/instantiate.go+++ b/src/go/go2go/instantiate.go@@ -232,8 +232,18 @@ func (t *translator) findTypeSpec(qid qualifiedIdent) (*ast.TypeSpec, error) {
return nil, fmt.Errorf("could not find Object for %q", qid)
}
spec, ok := t.importer.lookupTypeSpec(obj)
- if !ok {- return nil, fmt.Errorf("could not find type spec for %q", qid)+ for {+ if !ok {+ return nil, fmt.Errorf("could not find type spec for %q", qid)+ }+ if spec.TParams != nil {+ break+ }+ named, ok := t.importer.info.TypeOf(spec.Type).(*types.Named)+ if !ok || named.Obj().IsAlias() {+ break+ }+ spec, ok = t.importer.lookupTypeSpec(named.Obj())
}
return spec, nil
}
What version of Go are you using (go version)?
$ go version
go version devel +2faeebf4e5 Tue Jun 23 04:54:48 2020 +0000 linux/amd64
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
Thanks for pointing that out. I wasn't able to recreate the problem using the go-iter package, but I was able to create a small test case based on your description. The problem shown by that test case is now fixed on the dev.go2go branch.
If
package x
contains atype X
that is a parameterized type, andpackage y
contains atype Y = x.X
,go tool go2go build
will fail with a panic upon attempting to instantiatetype Y
.This fails because
spec *ast.TypeSpec
for an alias hasspec.TParams == nil
, which causes a panic in*translator.instantiateTypeDecl
. A workaround is to modify*translator.findTypeSpec
to resolve type aliases to the*ast.TypeSpec
of the underlying type: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?
What did you expect to see?
A successful build
What did you see instead?
The text was updated successfully, but these errors were encountered: