From ccaf3f55604469f5fa46f4dc1e81dc084f5c5fa4 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 19 Jun 2020 17:35:35 -0700 Subject: [PATCH] [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 --- src/go/go2go/instantiate.go | 10 ++++++---- test/gen/g028.go2 | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/gen/g028.go2 diff --git a/src/go/go2go/instantiate.go b/src/go/go2go/instantiate.go index 3abbb70951..538ad796d1 100644 --- a/src/go/go2go/instantiate.go +++ b/src/go/go2go/instantiate.go @@ -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, }, diff --git a/test/gen/g028.go2 b/test/gen/g028.go2 new file mode 100644 index 0000000000..076ec5b4bb --- /dev/null +++ b/test/gen/g028.go2 @@ -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)