Commit 170c1b47 authored by Alan Donovan's avatar Alan Donovan

go/types: record CallExpr result type even if argument is invalid

+ test

Fixes #15305

Change-Id: Ica657c00c92f0b19f0df7452cdbe5a95d23cc8a4
Reviewed-on: https://go-review.googlesource.com/22085Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent 67cdec00
......@@ -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")
}
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment