MCPcopy
hub / github.com/go-task/task / resolveMatrixRefs

Function resolveMatrixRefs

variables.go:457–487  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

455// below, intermittently leaking a value resolved for one caller into another
456// caller's expansion. See #2890.
457func 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
489func resolveEnumRefs(requires *ast.Requires, cache *templater.Cache) error {
490 if requires == nil || len(requires.Vars) == 0 {

Callers 2

itemsFromForFunction · 0.85

Calls 5

ResolveRefFunction · 0.92
ErrMethod · 0.80
DeepCopyMethod · 0.65
LenMethod · 0.45
AllMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…