mirror of https://github.com/golang/go.git
go/go2go: use types.RelativeTo rather than doing it by hand
Change-Id: I0891f034ef71311df007bb9aa527132d5b45c672 Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/771559 Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
feeeea1cda
commit
197db4cd00
|
|
@ -581,6 +581,7 @@ func (t *translator) translateExpr(pe *ast.Expr) {
|
|||
t.translateExpr(&e.Key)
|
||||
t.translateExpr(&e.Value)
|
||||
case *ast.ArrayType:
|
||||
t.translateExpr(&e.Len)
|
||||
t.translateExpr(&e.Elt)
|
||||
case *ast.StructType:
|
||||
t.translateFieldList(e.Fields)
|
||||
|
|
@ -931,7 +932,7 @@ func (t *translator) typeWithoutArgs(typ *types.Named) *types.Named {
|
|||
func (t *translator) typeListToASTList(typeList []types.Type) ([]types.Type, []ast.Expr) {
|
||||
argList := make([]ast.Expr, 0, len(typeList))
|
||||
for _, typ := range typeList {
|
||||
arg := ast.NewIdent(typ.String())
|
||||
arg := ast.NewIdent(types.TypeString(typ, types.RelativeTo(t.tpkg)))
|
||||
if named, ok := typ.(*types.Named); ok {
|
||||
if len(named.TArgs()) > 0 {
|
||||
var narg *ast.Ident
|
||||
|
|
@ -943,12 +944,6 @@ func (t *translator) typeListToASTList(typeList []types.Type) ([]types.Type, []a
|
|||
arg = ast.NewIdent(narg.Name)
|
||||
}
|
||||
}
|
||||
if named.Obj().Pkg() == t.tpkg {
|
||||
fields := strings.Split(arg.Name, ".")
|
||||
if len(fields) > 1 {
|
||||
arg = ast.NewIdent(fields[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
argList = append(argList, arg)
|
||||
t.setType(arg, typ)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
// run
|
||||
|
||||
// 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.
|
||||
|
||||
package main
|
||||
|
||||
type Recv <-chan int
|
||||
|
||||
type sliceOf(type E) interface {
|
||||
type []E
|
||||
}
|
||||
|
||||
func Append(type S sliceOf(T), T interface{})(s S, t ...T) S {
|
||||
return append(s, t...)
|
||||
}
|
||||
|
||||
func main() {
|
||||
a := Append([]Recv{nil}, Recv(nil))
|
||||
if len(a) != 2 || a[0] != nil || a[1] != nil {
|
||||
panic(a)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue