Skip to content

Commit

Permalink
fix internal template components link
Browse files Browse the repository at this point in the history
  • Loading branch information
wildum committed Jan 9, 2025
1 parent efbc4f9 commit 8781b37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/runtime/internal/controller/component_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,23 @@ func ComponentReferences(cn dag.Node, g *dag.Graph, l log.Logger, scope *vm.Scop
refs := make([]Reference, 0, len(traversals))
for _, t := range traversals {

// TODO: fix this
if len(t) == 1 {
continue
}

ref, resolveDiags := resolveTraversal(t, g)
componentRefMatch := !resolveDiags.HasErrors()

// we look for a match in the provided scope and the stdlib
_, scopeMatch := scope.Lookup(t[0].Name)

if !componentRefMatch && !scopeMatch {
diags = append(diags, resolveDiags...)
// TODO: this workaround ignores the traversal errors inside of the foreach block
// We are currently using the traversal at the root level to access the references from outside of the foreach block.
// This is quite handy but not perfect because:
// - it fails with the var
// - it fails at the root level to link two components that are inside of the template (because they are not evaluated at the root level)
// Both cases should be ignored so in theory that works well but it's not pretty + it won't show real errors.
// So we need to find a different approach to traverse the foreach node.
if _, ok := cn.(*ForeachConfigNode); !ok {
diags = append(diags, resolveDiags...)
}
continue
}

Expand Down
23 changes: 23 additions & 0 deletions internal/runtime/testdata/foreach/foreach_8.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Foreach with two components linked together.

-- main.alloy --
foreach "testForeach" {
collection = [10]
var = "num"

template {
testcomponents.passthrough "pt" {
input = num
lag = "1ms"
}
testcomponents.pulse "p" {
max = testcomponents.passthrough.pt.output
frequency = "10ms"
forward_to = [testcomponents.summation_receiver.sum.receiver]
}
}
}

// Similar to testcomponents.summation, but with a "receiver" export
testcomponents.summation_receiver "sum" {
}

0 comments on commit 8781b37

Please sign in to comment.