diff --git a/src/go/types/decl.go b/src/go/types/decl.go index 022f14484e..7c612ed9b5 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -772,6 +772,11 @@ func (check *Checker) declareTypeParams(tparams []*TypeName, names []*ast.Ident) check.declare(check.scope, name, tpar, check.scope.pos) // TODO(gri) check scope position tparams = append(tparams, tpar) } + + if check.conf.Trace && len(names) > 0 { + check.trace(names[0].Pos(), "type params = %v", tparams[len(tparams)-len(names):]) + } + return tparams } diff --git a/src/go/types/subst.go b/src/go/types/subst.go index 2a21811b0d..5abfc4d2a9 100644 --- a/src/go/types/subst.go +++ b/src/go/types/subst.go @@ -250,7 +250,7 @@ func (subst *subster) typ(typ Type) Type { // already instantiated dump(">>> %s already instantiated", t) - assert(len(t.targs) == len(t.targs)) + assert(len(t.targs) == len(t.tparams)) // For each (existing) type argument targ, determine if it needs // to be substituted; i.e., if it is or contains a type parameter // that has a type argument for it. @@ -282,7 +282,9 @@ func (subst *subster) typ(typ Type) Type { // TODO(gri) revisit name creation (function local types, etc.) and factor out // (also, stripArgNames call is an awful hack) - name := stripArgNames(TypeString(t, nil)) + "<" + typeListString(new_targs) + ">" + var buf bytes.Buffer + writeTypeName(&buf, t.obj, nil) + name := stripArgNames(buf.String()) + "<" + typeListString(new_targs) + ">" dump(">>> new type name: %s", name) if tname, found := subst.check.typMap[name]; found { dump(">>> instantiated %s found", tname) diff --git a/src/go/types/typestring.go b/src/go/types/typestring.go index 3b771a0e27..e6fbacd064 100644 --- a/src/go/types/typestring.go +++ b/src/go/types/typestring.go @@ -259,7 +259,10 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) { case *Named: writeTypeName(buf, t.obj, qf) - if t.tparams != nil { + // Don't write type parameter list again if we have an instantiated type, + // recognized by a closing '>'. + // TODO(gri) clean up - this is too subtle a hack and too dependent on subst. + if buf.Bytes()[buf.Len()-1] != '>' && t.tparams != nil { writeTParamList(buf, t.tparams, qf, visited) }