From 39a4b4d41345cdafa08459500c7056377397a334 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Thu, 21 Dec 2023 10:04:45 -0600 Subject: [PATCH] fix: variable propagation (#1437) --- internal/compiler/v3/compiler_v3.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/compiler/v3/compiler_v3.go b/internal/compiler/v3/compiler_v3.go index 2b62347d..164dd81f 100644 --- a/internal/compiler/v3/compiler_v3.go +++ b/internal/compiler/v3/compiler_v3.go @@ -68,17 +68,23 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat } newVar.Sh = tr.Replace(v.Sh) newVar.Dir = v.Dir - if err := tr.Err(); err != nil { - return err - } // If the variable should not be evaluated, but is nil, set it to an empty string // This stops empty interface errors when using the templater to replace values later if !evaluateShVars && newVar.Value == nil { result.Set(k, taskfile.Var{Value: ""}) return nil } + // If the variable should not be evaluated and it is set, we can set it and return + if !evaluateShVars { + result.Set(k, taskfile.Var{Value: newVar.Value}) + return nil + } + // Now we can check for errors since we've handled all the cases when we don't want to evaluate + if err := tr.Err(); err != nil { + return err + } // If the variable is not dynamic, we can set it and return - if !evaluateShVars || newVar.Value != nil || newVar.Sh == "" { + if newVar.Value != nil || newVar.Sh == "" { result.Set(k, taskfile.Var{Value: newVar.Value}) return nil }