diff --git a/src/go/go2go/instantiate.go b/src/go/go2go/instantiate.go index 1090465365..9a4c904bda 100644 --- a/src/go/go2go/instantiate.go +++ b/src/go/go2go/instantiate.go @@ -760,7 +760,7 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { if ln == e.Len && elt == e.Elt { return e } - return &ast.ArrayType{ + r = &ast.ArrayType{ Lbrack: e.Lbrack, Len: ln, Elt: elt, @@ -770,7 +770,7 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { if fields == e.Fields { return e } - return &ast.StructType{ + r = &ast.StructType{ Struct: e.Struct, Fields: fields, Incomplete: e.Incomplete, @@ -781,7 +781,7 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { if e.TParams == nil && params == e.Params && results == e.Results { return e } - return &ast.FuncType{ + r = &ast.FuncType{ Func: e.Func, TParams: nil, Params: params, @@ -794,7 +794,7 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { if methods == e.Methods && !typesChanged { return e } - return &ast.InterfaceType{ + r = &ast.InterfaceType{ Interface: e.Interface, Methods: mergeFieldList(methods, types), Incomplete: e.Incomplete, @@ -805,7 +805,7 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { if key == e.Key && value == e.Value { return e } - return &ast.MapType{ + r = &ast.MapType{ Map: e.Map, Key: key, Value: value, @@ -815,7 +815,7 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { if value == e.Value { return e } - return &ast.ChanType{ + r = &ast.ChanType{ Begin: e.Begin, Arrow: e.Arrow, Dir: e.Dir, @@ -825,8 +825,6 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr { panic(fmt.Sprintf("unimplemented Expr %T", e)) } - // We fall down to here for expressions that are not types. - if et := t.lookupType(e); et != nil { t.setType(r, t.instantiateType(ta, et)) } diff --git a/test/gen/g007.go2 b/test/gen/g007.go2 new file mode 100644 index 0000000000..c9d72b3888 --- /dev/null +++ b/test/gen/g007.go2 @@ -0,0 +1,20 @@ +// 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. + +// Using a type literal based on a type parameter as a type argument +// in a result. + +package p + +type S(type T) struct { + f T +} + +func SliceS(type T)() S([]T) { + return S([]T){nil} +} + +var V = SliceS(int)()