Skip to content

Commit dfb538c

Browse files
[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 <[email protected]>
1 parent 404a12f commit dfb538c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/go/go2go/rewrite.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ func (t *translator) translateTypeInstantiation(pe *ast.Expr) {
857857
qid := t.instantiatedIdent(call)
858858
typ := t.lookupType(call.Fun).(*types.Named)
859859
argList, typeList, typeArgs := t.instantiationTypes(call)
860+
if t.err != nil {
861+
return
862+
}
860863
if !typeArgs {
861864
panic("no type arguments for type")
862865
}
@@ -950,6 +953,10 @@ func (t *translator) instantiationTypes(call *ast.CallExpr) (argList []ast.Expr,
950953
argList = call.Args
951954
typeList = make([]types.Type, 0, len(argList))
952955
for _, arg := range argList {
956+
if id, ok := arg.(*ast.Ident); ok && id.Name == "_" {
957+
t.err = fmt.Errorf("%s: go2go tool does not support using _ here", t.fset.Position(arg.Pos()))
958+
return
959+
}
953960
if at := t.lookupType(arg); at == nil {
954961
panic(fmt.Sprintf("%s: no type found for %T %v", t.fset.Position(arg.Pos()), arg, arg))
955962
} else {

test/gen/err006.go2

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// errorcheck
2+
3+
// Copyright 2020 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 39743.
8+
package p
9+
10+
type S(type T) struct{}
11+
12+
func (s S(_)) M() {} // ERROR "_"
13+
14+
func F() {
15+
S(int){}.M()
16+
}

0 commit comments

Comments
 (0)