diff --git a/src/go/go2go/rewrite.go b/src/go/go2go/rewrite.go index 7735772c44..36a4ed58b5 100644 --- a/src/go/go2go/rewrite.go +++ b/src/go/go2go/rewrite.go @@ -857,6 +857,9 @@ func (t *translator) translateTypeInstantiation(pe *ast.Expr) { qid := t.instantiatedIdent(call) typ := t.lookupType(call.Fun).(*types.Named) argList, typeList, typeArgs := t.instantiationTypes(call) + if t.err != nil { + return + } if !typeArgs { panic("no type arguments for type") } @@ -950,6 +953,10 @@ func (t *translator) instantiationTypes(call *ast.CallExpr) (argList []ast.Expr, argList = call.Args typeList = make([]types.Type, 0, len(argList)) for _, arg := range argList { + if id, ok := arg.(*ast.Ident); ok && id.Name == "_" { + t.err = fmt.Errorf("%s: go2go tool does not support using _ here", t.fset.Position(arg.Pos())) + return + } if at := t.lookupType(arg); at == nil { panic(fmt.Sprintf("%s: no type found for %T %v", t.fset.Position(arg.Pos()), arg, arg)) } else { diff --git a/test/gen/err006.go2 b/test/gen/err006.go2 new file mode 100644 index 0000000000..163369c50e --- /dev/null +++ b/test/gen/err006.go2 @@ -0,0 +1,16 @@ +// errorcheck + +// 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 39743. +package p + +type S(type T) struct{} + +func (s S(_)) M() {} // ERROR "_" + +func F() { + S(int){}.M() +}