resolveMatrixRefs resolves any `ref:` rows in matrix and returns a new Matrix with those rows populated. It must not mutate the matrix passed in: that matrix is part of the shared, cached Task AST, and concurrent invocations of the same task (e.g. via parallel deps) call this with the same *ast.Matr
(matrix *ast.Matrix, cache *templater.Cache)
| 455 | // below, intermittently leaking a value resolved for one caller into another |
| 456 | // caller's expansion. See #2890. |
| 457 | func resolveMatrixRefs(matrix *ast.Matrix, cache *templater.Cache) (*ast.Matrix, error) { |
| 458 | if matrix.Len() == 0 { |
| 459 | return matrix, nil |
| 460 | } |
| 461 | hasRef := false |
| 462 | for _, row := range matrix.All() { |
| 463 | if row.Ref != "" { |
| 464 | hasRef = true |
| 465 | break |
| 466 | } |
| 467 | } |
| 468 | if !hasRef { |
| 469 | return matrix, nil |
| 470 | } |
| 471 | resolved := matrix.DeepCopy() |
| 472 | for _, row := range resolved.All() { |
| 473 | if row.Ref != "" { |
| 474 | v := templater.ResolveRef(row.Ref, cache) |
| 475 | if cache.Err() != nil { |
| 476 | return nil, cache.Err() |
| 477 | } |
| 478 | switch value := v.(type) { |
| 479 | case []any: |
| 480 | row.Value = value |
| 481 | default: |
| 482 | return nil, fmt.Errorf("matrix reference %q must resolve to a list", row.Ref) |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | return resolved, nil |
| 487 | } |
| 488 | |
| 489 | func resolveEnumRefs(requires *ast.Requires, cache *templater.Cache) error { |
| 490 | if requires == nil || len(requires.Vars) == 0 { |
searching dependent graphs…