aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/expr.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/noder/expr.go')
-rw-r--r--src/cmd/compile/internal/noder/expr.go63
1 files changed, 7 insertions, 56 deletions
diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go
index 7dbbc88f8fb..9cd9545b759 100644
--- a/src/cmd/compile/internal/noder/expr.go
+++ b/src/cmd/compile/internal/noder/expr.go
@@ -250,44 +250,6 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
// only be fully transformed once it has an instantiated type.
n := ir.NewSelectorExpr(pos, ir.OXDOT, x, typecheck.Lookup(expr.Sel.Value))
typed(g.typ(typ), n)
-
- // Fill in n.Selection for a generic method reference or a bound
- // interface method, even though we won't use it directly, since it
- // is useful for analysis. Specifically do not fill in for fields or
- // other interfaces methods (method call on an interface value), so
- // n.Selection being non-nil means a method reference for a generic
- // type or a method reference due to a bound.
- obj2 := g.info.Selections[expr].Obj()
- sig := types2.AsSignature(obj2.Type())
- if sig == nil || sig.Recv() == nil {
- return n
- }
- index := g.info.Selections[expr].Index()
- last := index[len(index)-1]
- // recvType is the receiver of the method being called. Because of the
- // way methods are imported, g.obj(obj2) doesn't work across
- // packages, so we have to lookup the method via the receiver type.
- recvType := deref2(sig.Recv().Type())
- if types2.AsInterface(recvType.Underlying()) != nil {
- fieldType := n.X.Type()
- for _, ix := range index[:len(index)-1] {
- fieldType = deref(fieldType).Field(ix).Type
- }
- if fieldType.Kind() == types.TTYPEPARAM {
- n.Selection = fieldType.Bound().AllMethods().Index(last)
- //fmt.Printf(">>>>> %v: Bound call %v\n", base.FmtPos(pos), n.Sel)
- } else {
- assert(fieldType.Kind() == types.TINTER)
- //fmt.Printf(">>>>> %v: Interface call %v\n", base.FmtPos(pos), n.Sel)
- }
- return n
- }
-
- recvObj := types2.AsNamed(recvType).Obj()
- recv := g.pkg(recvObj.Pkg()).Lookup(recvObj.Name()).Def
- n.Selection = recv.Type().Methods().Index(last)
- //fmt.Printf(">>>>> %v: Method call %v\n", base.FmtPos(pos), n.Sel)
-
return n
}
@@ -344,7 +306,7 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
if wantPtr {
recvType2Base = types2.AsPointer(recvType2).Elem()
}
- if types2.AsNamed(recvType2Base).TParams().Len() > 0 {
+ if types2.AsNamed(recvType2Base).TypeParams().Len() > 0 {
// recvType2 is the original generic type that is
// instantiated for this method call.
// selinfo.Recv() is the instantiated type
@@ -360,12 +322,10 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
n.(*ir.SelectorExpr).Selection.Nname = method
typed(method.Type(), n)
- // selinfo.Targs() are the types used to
- // instantiate the type of receiver
- targs2 := getTargs(selinfo)
- targs := make([]ir.Node, targs2.Len())
+ xt := deref(x.Type())
+ targs := make([]ir.Node, len(xt.RParams()))
for i := range targs {
- targs[i] = ir.TypeNode(g.typ(targs2.At(i)))
+ targs[i] = ir.TypeNode(xt.RParams()[i])
}
// Create function instantiation with the type
@@ -388,16 +348,6 @@ func (g *irgen) selectorExpr(pos src.XPos, typ types2.Type, expr *syntax.Selecto
return n
}
-// getTargs gets the targs associated with the receiver of a selected method
-func getTargs(selinfo *types2.Selection) *types2.TypeList {
- r := deref2(selinfo.Recv())
- n := types2.AsNamed(r)
- if n == nil {
- base.Fatalf("Incorrect type for selinfo %v", selinfo)
- }
- return n.TArgs()
-}
-
func (g *irgen) exprList(expr syntax.Expr) []ir.Node {
return g.exprs(unpackListExpr(expr))
}
@@ -440,9 +390,10 @@ func (g *irgen) compLit(typ types2.Type, lit *syntax.CompositeLit) ir.Node {
} else {
key = g.expr(elem.Key)
}
- exprs[i] = ir.NewKeyExpr(g.pos(elem), key, g.expr(elem.Value))
+ value := wrapname(g.pos(elem.Value), g.expr(elem.Value))
+ exprs[i] = ir.NewKeyExpr(g.pos(elem), key, value)
default:
- exprs[i] = g.expr(elem)
+ exprs[i] = wrapname(g.pos(elem), g.expr(elem))
}
}