go/go2go: record types of instantiated AST types

Otherwise we don't know the type of an instantiated type in an
instantiated function.

Change-Id: If7eb75dd920a3c9fc1b6992addcd3b91b6d425a9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715718
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Ian Lance Taylor 2020-04-10 12:25:39 -07:00 committed by Robert Griesemer
parent 760a3244a7
commit c2d8b59433
2 changed files with 26 additions and 8 deletions

View File

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

20
test/gen/g007.go2 Normal file
View File

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