From e5f49b1c9f0ba4fee8e587fedf534720db655b63 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 31 May 2013 11:22:00 -0700 Subject: [PATCH] go.tools/go/types: typecheck call arguments even if the call doesn't typecheck This provides better partial type information in case of type errors. R=r CC=golang-dev https://golang.org/cl/9835049 --- go/types/check.go | 2 ++ go/types/expr.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/go/types/check.go b/go/types/check.go index 0032726e59..472efe2da8 100644 --- a/go/types/check.go +++ b/go/types/check.go @@ -50,12 +50,14 @@ type checker struct { func (check *checker) callIdent(id *ast.Ident, obj Object) { if f := check.ctxt.Ident; f != nil { + assert(id != nil) f(id, obj) } } func (check *checker) callImplicitObj(node ast.Node, obj Object) { if f := check.ctxt.ImplicitObj; f != nil { + assert(node != nil && obj != nil) f(node, obj) } } diff --git a/go/types/expr.go b/go/types/expr.go index 157392b93f..1c1708b987 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -1018,6 +1018,7 @@ func (check *checker) callExpr(x *operand) { // This is not the case yet. if check.ctxt.Expr != nil { + assert(x.expr != nil && typ != nil) check.ctxt.Expr(x.expr, typ, val) } } @@ -1536,9 +1537,17 @@ func (check *checker) rawExpr(x *operand, e ast.Expr, hint Type, iota int, cycle case *ast.CallExpr: check.exprOrType(x, e.Fun, iota, false) if x.mode == invalid { + // We don't have a valid call or conversion but we have list of arguments. + // Typecheck them independently for better partial type information in + // the presence of type errors. + for _, arg := range e.Args { + check.expr(x, arg, nil, iota) + } goto Error + } else if x.mode == typexpr { check.conversion(x, e, x.typ, iota) + } else if sig, ok := x.typ.Underlying().(*Signature); ok { // check parameters