Skip to content

Commit

Permalink
interp: wrap source functions when used as input parameters.
Browse files Browse the repository at this point in the history
It allows to use interpreter functions as parameters in the runtime,
even for defered callbacks, or when passed as empty interfaces,
as for runtime.SetFinalizer.

Fixes traefik#1503
  • Loading branch information
mvertes committed Feb 8, 2023
1 parent 0e3ea57 commit 42d3dde
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions _test/fun28.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"runtime"
)

type T struct {
name string
}

func finalize(t *T) { println("finalize") }

func newT() *T {
t := new(T)
runtime.SetFinalizer(t, finalize)
return t
}

func main() {
t := newT()
println(t != nil)
}

// Output:
// true
2 changes: 2 additions & 0 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,8 @@ func callBin(n *node) {
values = append(values, genValue(c))
case isInterfaceSrc(c.typ):
values = append(values, genValueInterfaceValue(c))
case isFuncSrc(c.typ):
values = append(values, genFunctionWrapper(c))
case c.typ.cat == arrayT || c.typ.cat == variadicT:
if isEmptyInterface(c.typ.val) {
values = append(values, genValueArray(c))
Expand Down

0 comments on commit 42d3dde

Please sign in to comment.