fix: do not confuse function call with type conversion

Use node action to better discriminate between function call and type
conversion which have the same pattern at AST level.

Fixes #960.
This commit is contained in:
Marc Vertes
2020-11-18 14:56:05 +01:00
committed by GitHub
parent 38a7331bf9
commit 6da1107c39
2 changed files with 19 additions and 2 deletions

17
_test/fun26.go Normal file
View File

@@ -0,0 +1,17 @@
package main
type F func() (int, error)
func f1() (int, error) { return 3, nil }
func f2(a string, f F) {
c, _ := f()
println(a, c)
}
func main() {
f2("hello", F(f1))
}
// Output:
// hello 3

View File

@@ -2333,7 +2333,7 @@ func isCall(n *node) bool {
}
func isBinCall(n *node) bool {
return n.kind == callExpr && n.child[0].typ.cat == valueT && n.child[0].typ.rtype.Kind() == reflect.Func
return isCall(n) && n.child[0].typ.cat == valueT && n.child[0].typ.rtype.Kind() == reflect.Func
}
func mustReturnValue(n *node) bool {
@@ -2349,7 +2349,7 @@ func mustReturnValue(n *node) bool {
}
func isRegularCall(n *node) bool {
return n.kind == callExpr && n.child[0].typ.cat == funcT
return isCall(n) && n.child[0].typ.cat == funcT
}
func variadicPos(n *node) int {