Skip to content

Commit 6da1107

Browse files
authored
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.
1 parent 38a7331 commit 6da1107

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

_test/fun26.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
type F func() (int, error)
4+
5+
func f1() (int, error) { return 3, nil }
6+
7+
func f2(a string, f F) {
8+
c, _ := f()
9+
println(a, c)
10+
}
11+
12+
func main() {
13+
f2("hello", F(f1))
14+
}
15+
16+
// Output:
17+
// hello 3

interp/cfg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ func isCall(n *node) bool {
23332333
}
23342334

23352335
func isBinCall(n *node) bool {
2336-
return n.kind == callExpr && n.child[0].typ.cat == valueT && n.child[0].typ.rtype.Kind() == reflect.Func
2336+
return isCall(n) && n.child[0].typ.cat == valueT && n.child[0].typ.rtype.Kind() == reflect.Func
23372337
}
23382338

23392339
func mustReturnValue(n *node) bool {
@@ -2349,7 +2349,7 @@ func mustReturnValue(n *node) bool {
23492349
}
23502350

23512351
func isRegularCall(n *node) bool {
2352-
return n.kind == callExpr && n.child[0].typ.cat == funcT
2352+
return isCall(n) && n.child[0].typ.cat == funcT
23532353
}
23542354

23552355
func variadicPos(n *node) int {

0 commit comments

Comments
 (0)