Skip to content

Commit 96a96a9

Browse files
committed
cmd/compile: remove types2.(*Selection).TArgs(), now that instance bug seems fixed
Previously, we would sometimes see an internal (*instance) type for a receiver of a types2 method, which was a bug. To deal with that, we put in an extra (*Selection).TArgs() method. However, that (*instance) type is no longer showing up for receivers, so we can remove the types2 method we added and do the work with existing types2 API methods. Change-Id: I03e68f5bbaaf82fe706b6efecbb02e951bbd3cd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/298869 Run-TryBot: Dan Scales <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Trust: Dan Scales <[email protected]>
1 parent d891ebd commit 96a96a9

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/cmd/compile/internal/noder/expr.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
253253

254254
// selinfo.Targs() are the types used to
255255
// instantiate the type of receiver
256-
targs2 := selinfo.TArgs()
256+
targs2 := getTargs(selinfo)
257257
targs := make([]ir.Node, len(targs2))
258258
for i, targ2 := range targs2 {
259259
targs[i] = ir.TypeNode(g.typ(targ2))
@@ -279,6 +279,19 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
279279
return n
280280
}
281281

282+
// getTargs gets the targs associated with the receiver of a selected method
283+
func getTargs(selinfo *types2.Selection) []types2.Type {
284+
r := selinfo.Recv()
285+
if p := types2.AsPointer(r); p != nil {
286+
r = p.Elem()
287+
}
288+
n := types2.AsNamed(r)
289+
if n == nil {
290+
base.Fatalf("Incorrect type for selinfo %v", selinfo)
291+
}
292+
return n.TArgs()
293+
}
294+
282295
func (g *irgen) exprList(expr syntax.Expr) []ir.Node {
283296
switch expr := expr.(type) {
284297
case nil:

src/cmd/compile/internal/types2/selection.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,6 @@ func (s *Selection) Kind() SelectionKind { return s.kind }
5151
// Recv returns the type of x in x.f.
5252
func (s *Selection) Recv() Type { return s.recv }
5353

54-
// Work-around for a compiler issue where an (*instance) escapes.
55-
// TODO(gri): Is this still needed?
56-
func (s *Selection) TArgs() []Type {
57-
r := s.recv
58-
if p := asPointer(r); p != nil {
59-
r = p.Elem()
60-
}
61-
if n := asNamed(r); n != nil {
62-
return n.TArgs()
63-
}
64-
// The base type (after skipping any pointer) must be a Named type. The
65-
// bug is that sometimes it can be an instance type (which is supposed to
66-
// be an internal type only).
67-
return r.(*instance).targs
68-
}
69-
7054
// Obj returns the object denoted by x.f; a *Var for
7155
// a field selection, and a *Func in all other cases.
7256
func (s *Selection) Obj() Object { return s.obj }

0 commit comments

Comments
 (0)