Skip to content

Commit

Permalink
fix: do not confuse function call with type conversion
Browse files Browse the repository at this point in the history
Use node action to better discriminate between function call and type
conversion which have the same pattern at AST level.

Fixes #960.
  • Loading branch information
mvertes authored Nov 18, 2020
1 parent 38a7331 commit 6da1107
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions _test/fun26.go
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 6da1107

Please sign in to comment.