Skip to content

Commit

Permalink
[dev.go2go] go/go2go: update name of embedded pointer to instantiation
Browse files Browse the repository at this point in the history
Fixes #39774

Change-Id: Icb2948ae19e06a3766e7edb01ef40de50e7aca7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/239702
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
ianlancetaylor committed Jun 24, 2020
1 parent 2dc2987 commit fa201df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/go/go2go/instantiate.go
Expand Up @@ -819,7 +819,13 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr {
if len(f.Names) > 0 {
continue
}
id, ok := f.Type.(*ast.Ident)
isPtr := false
ftyp := f.Type
if star, ok := ftyp.(*ast.StarExpr); ok {
ftyp = star.X
isPtr = true
}
id, ok := ftyp.(*ast.Ident)
if !ok {
continue
}
Expand All @@ -832,6 +838,9 @@ func (t *translator) instantiateExpr(ta *typeArgs, e ast.Expr) ast.Expr {
continue
}
instType := t.instantiateType(ta, typeParam)
if isPtr {
instType = types.NewPointer(instType)
}
str := types.TypeString(instType, relativeTo(t.tpkg))
newField := &ast.Field{
Doc: f.Doc,
Expand Down
20 changes: 20 additions & 0 deletions test/gen/g034.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.

package p

type I interface{}

type S(type T) struct {
*T
}

func F() {
v := S(I){}
if v.T != nil {
panic(v)
}
}

0 comments on commit fa201df

Please sign in to comment.