@@ -424,6 +424,10 @@ func doEval(ir *interp.Interp, code string) (val []interface{}, err error) {
424424 // Check if the last node is an expression. If the last node is not an expression then nothing
425425 // is returned as a value. For example evaluating a function declaration shouldn't return a value but
426426 // just have the side effect of declaring the function.
427+ //
428+ // This is actually needed only for gomacro classic interpreter
429+ // (the fast interpreter already returns values only for expressions)
430+ // but retained for compatibility.
427431 var srcEndsWithExpr bool
428432 if len (nodes ) > 0 {
429433 _ , srcEndsWithExpr = nodes [len (nodes )- 1 ].(ast.Expr )
@@ -433,18 +437,11 @@ func doEval(ir *interp.Interp, code string) (val []interface{}, err error) {
433437 compiledSrc := ir .CompileAst (srcAst )
434438
435439 // Evaluate the code.
436- result , results := ir .RunExpr (compiledSrc )
440+ results := base . PackValues ( ir .RunExpr (compiledSrc ) )
437441
438442 // If the source ends with an expression, then the result of the execution is the value of the expression. In the
439443 // event that all return values are nil, the result is also nil.
440444 if srcEndsWithExpr {
441- // `len(results) == 0` implies a single result stored in `result`.
442- if len (results ) == 0 {
443- if val := base .ValueInterface (result ); val != nil {
444- return []interface {}{val }, nil
445- }
446- return nil , nil
447- }
448445
449446 // Count the number of non-nil values in the output. If they are all nil then the output is skipped.
450447 nonNilCount := 0
@@ -460,7 +457,6 @@ func doEval(ir *interp.Interp, code string) (val []interface{}, err error) {
460457 if nonNilCount > 0 {
461458 return values , nil
462459 }
463- return nil , nil
464460 }
465461
466462 return nil , nil
0 commit comments