[dev.go2go] go/go2go: don't crash on an unnamed receiver

Fixes #39707

Change-Id: I20e5fe2990ceda5429f1a22edf48494d2c6496a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/239159
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Ian Lance Taylor 2020-06-19 17:35:35 -07:00
parent cab5f803e8
commit ccaf3f5560
2 changed files with 20 additions and 4 deletions

View File

@ -197,16 +197,18 @@ func (t *translator) instantiateTypeDecl(qid qualifiedIdent, typ *types.Named, a
}
tparams := rtyp.(*ast.CallExpr).Args
ta := typeArgsFromExprs(t, astTypes, typeTypes, tparams)
var names []*ast.Ident
if mnames := mast.Recv.List[0].Names; len(mnames) > 0 {
names = []*ast.Ident{mnames[0]}
}
newDecl := &ast.FuncDecl{
Doc: mast.Doc,
Recv: &ast.FieldList{
Opening: mast.Recv.Opening,
List: []*ast.Field{
{
Doc: mast.Recv.List[0].Doc,
Names: []*ast.Ident{
mast.Recv.List[0].Names[0],
},
Doc: mast.Recv.List[0].Doc,
Names: names,
Type: newRtype,
Comment: mast.Recv.List[0].Comment,
},

14
test/gen/g028.go2 Normal file
View File

@ -0,0 +1,14 @@
// compile
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 39688.
package p
type S(type T) T
func (*S(T)) M() {}
var V S(int)