]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: record CallExpr result type even if argument is invalid
authorAlan Donovan <adonovan@google.com>
Thu, 14 Apr 2016 17:41:32 +0000 (13:41 -0400)
committerAlan Donovan <adonovan@google.com>
Thu, 14 Apr 2016 18:02:31 +0000 (18:02 +0000)
+ test

Fixes #15305

Change-Id: Ica657c00c92f0b19f0df7452cdbe5a95d23cc8a4
Reviewed-on: https://go-review.googlesource.com/22085
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/api_test.go
src/go/types/call.go

index 9573d80a17dc8af554a2c99f4b83fae42e44ae7d..8b8ae1bb5d038c9928c6d08f55877fff0876bd0c 100644 (file)
@@ -1059,3 +1059,28 @@ func TestIdentical_issue15173(t *testing.T) {
                }
        }
 }
+
+func TestIssue15305(t *testing.T) {
+       const src = "package p; func f() int16; var _ = f(undef)"
+       fset := token.NewFileSet()
+       f, err := parser.ParseFile(fset, "issue15305.go", src, 0)
+       if err != nil {
+               t.Fatal(err)
+       }
+       conf := Config{
+               Error: func(err error) {}, // allow errors
+       }
+       info := &Info{
+               Types: make(map[ast.Expr]TypeAndValue),
+       }
+       conf.Check("p", fset, []*ast.File{f}, info) // ignore result
+       for e, tv := range info.Types {
+               if _, ok := e.(*ast.CallExpr); ok {
+                       if tv.Type != Typ[Int16] {
+                               t.Errorf("CallExpr has type %v, want int16", tv.Type)
+                       }
+                       return
+               }
+       }
+       t.Errorf("CallExpr has no type")
+}
index 8aeb862993f8520f590a158d7ac8cde53105e04a..45f3e9a6056ebdd5f894168e31c2960c5e40b168 100644 (file)
@@ -62,14 +62,12 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind {
                }
 
                arg, n, _ := unpack(func(x *operand, i int) { check.multiExpr(x, e.Args[i]) }, len(e.Args), false)
-               if arg == nil {
+               if arg != nil {
+                       check.arguments(x, e, sig, arg, n)
+               } else {
                        x.mode = invalid
-                       x.expr = e
-                       return statement
                }
 
-               check.arguments(x, e, sig, arg, n)
-
                // determine result
                switch sig.results.Len() {
                case 0:
@@ -81,6 +79,7 @@ func (check *Checker) call(x *operand, e *ast.CallExpr) exprKind {
                        x.mode = value
                        x.typ = sig.results
                }
+
                x.expr = e
                check.hasCallOrRecv = true