@@ -251,12 +251,13 @@ func (vm *VM) Run(program *Program, env interface{}) interface{} {
251251 in := make ([]reflect.Value , call .Size )
252252 for i := call .Size - 1 ; i >= 0 ; i -- {
253253 param := vm .pop ()
254- if param == nil {
255- // In case of nil interface{} ( nil type) use this hack,
254+ if param == nil && reflect . TypeOf ( param ) == nil {
255+ // In case of nil value and nil type use this hack,
256256 // otherwise reflect.Call will panic on zero value.
257- param = reflect .ValueOf (& in ).Elem ()
257+ in [i ] = reflect .ValueOf (& param ).Elem ()
258+ } else {
259+ in [i ] = reflect .ValueOf (param )
258260 }
259- in [i ] = reflect .ValueOf (param )
260261 }
261262 out := fetchFn (env , call .Name ).Call (in )
262263 vm .push (out [0 ].Interface ())
@@ -275,12 +276,13 @@ func (vm *VM) Run(program *Program, env interface{}) interface{} {
275276 in := make ([]reflect.Value , call .Size )
276277 for i := call .Size - 1 ; i >= 0 ; i -- {
277278 param := vm .pop ()
278- if param == nil {
279- // In case of nil interface{} ( nil type) use this hack,
279+ if param == nil && reflect . TypeOf ( param ) == nil {
280+ // In case of nil value and nil type use this hack,
280281 // otherwise reflect.Call will panic on zero value.
281- param = reflect .ValueOf (& in ).Elem ()
282+ in [i ] = reflect .ValueOf (& param ).Elem ()
283+ } else {
284+ in [i ] = reflect .ValueOf (param )
282285 }
283- in [i ] = reflect .ValueOf (param )
284286 }
285287 out := fetchFn (vm .pop (), call .Name ).Call (in )
286288 vm .push (out [0 ].Interface ())
0 commit comments