Skip to content

Commit 0052ad2

Browse files
authored
fix: do not re-evaluate variables for defer: (#2418)
1 parent af1e755 commit 0052ad2

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

task.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (e *Executor) RunTask(ctx context.Context, call *Call) error {
210210

211211
for i := range t.Cmds {
212212
if t.Cmds[i].Defer {
213-
defer e.runDeferred(t, call, i, &deferredExitCode)
213+
defer e.runDeferred(t, call, i, t.Vars, &deferredExitCode)
214214
continue
215215
}
216216

@@ -277,17 +277,11 @@ func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error {
277277
return g.Wait()
278278
}
279279

280-
func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, deferredExitCode *uint8) {
280+
func (e *Executor) runDeferred(t *ast.Task, call *Call, i int, vars *ast.Vars, deferredExitCode *uint8) {
281281
ctx, cancel := context.WithCancel(context.Background())
282282
defer cancel()
283283

284-
origTask, err := e.GetTask(call)
285-
if err != nil {
286-
return
287-
}
288-
289284
cmd := t.Cmds[i]
290-
vars, _ := e.Compiler.GetVariables(origTask, call)
291285
cache := &templater.Cache{Vars: vars}
292286
extra := map[string]any{}
293287

0 commit comments

Comments
 (0)