[dev.go2go] go/go2go: don't permit underscore as type argument

The go/types package doesn't give us an easy way to get the type,
so just reject it.

Fixes #39743

Change-Id: I5404c10baede0fd2cf67980b06fbebd214a50dff
Reviewed-on: https://go-review.googlesource.com/c/go/+/239382
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Ian Lance Taylor 2020-06-22 16:28:40 -07:00
parent 404a12f056
commit dfb538cec8
2 changed files with 23 additions and 0 deletions

View File

@ -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 {

16
test/gen/err006.go2 Normal file
View File

@ -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()
}