From e7016436a68110719372ace23ad9280ab4cfa432 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 31 Jul 2013 21:31:46 -0400 Subject: [PATCH] go.tools/ssa: accommodate go/types changes to value,ok-mode inferred types. The required changes were surprisingly minimal (I was hoping for a net code deletion) because ssa is essentially doing its own type inference for the three value,ok operators---and it continues to have to do so. To see why, consider: var i interface{}; var ok bool i, ok := (map[string]string)(nil)[""] Before, go/types inferred interface{} for the RHS of the assignment, and now it infers (interface{}, bool), yet neither of these is what ssa needs: it needs to know that the map values were strings so that it can emit a lookup of the right type followed by a conversion from string to interface{}. TBR=gri CC=golang-dev https://golang.org/cl/11988044 --- ssa/builder.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ssa/builder.go b/ssa/builder.go index 04e792fc73..a7406796f4 100644 --- a/ssa/builder.go +++ b/ssa/builder.go @@ -225,7 +225,8 @@ func (b *builder) exprN(fn *Function, e ast.Expr) Value { tuple = fn.emit(lookup) case *ast.TypeAssertExpr: - return emitTypeTest(fn, b.expr(fn, e.X), fn.Pkg.typeOf(e), e.Lparen) + t := fn.Pkg.typeOf(e).(*types.Tuple).At(0).Type() + return emitTypeTest(fn, b.expr(fn, e.X), t, e.Lparen) case *ast.UnaryExpr: // must be receive <- typ = fn.Pkg.typeOf(e.X).Underlying().(*types.Chan).Elem() @@ -393,7 +394,7 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue { last := len(sel.Index()) - 1 return &address{ addr: emitFieldSelection(fn, v, sel.Index()[last], true, e.Sel.Pos()), - expr: e.Sel, // TODO plus e itself? + expr: e.Sel, object: sel.Obj(), } }