fix(templateengine): SemanticValidator accepts composition-delegated CallScript (Children[x].CallScript leaf-name match)

This commit is contained in:
Joseph Doherty
2026-06-17 12:43:17 -04:00
parent 0e989c867d
commit 670b607acb
2 changed files with 63 additions and 2 deletions
@@ -40,6 +40,21 @@ public class SemanticValidator
var scriptNames = new HashSet<string>(
configuration.Scripts.Select(s => s.CanonicalName), StringComparer.Ordinal);
// Composition-delegated CallScript: a machine script may invoke a composed
// child's script via Children["X"].CallScript("Y") (often with a DYNAMIC child
// name, e.g. Children[side + "MESReceiver"]). ExtractCalls captures only the
// literal leaf "Y"; the actual flattened script is the composed canonical
// "X.Y". Since the child segment is dynamic it cannot be statically resolved,
// so we accept the call as existing when ANY composed script has that leaf
// name. The positional arg-count/type checks already self-skip for these
// (their canonical name "X.Y" is not the literal key "Y" in the param map).
var composedLeafNames = new HashSet<string>(
configuration.Scripts
.Select(s => s.CanonicalName)
.Where(n => n.Contains('.'))
.Select(n => n[(n.LastIndexOf('.') + 1)..]),
StringComparer.Ordinal);
var sharedScriptNames = new HashSet<string>(
(sharedScripts ?? []).Select(s => s.CanonicalName), StringComparer.Ordinal);
@@ -92,8 +107,11 @@ public class SemanticValidator
}
else
{
// CallScript targets must reference existing instance scripts
if (!scriptNames.Contains(call.TargetName))
// CallScript targets must reference an existing instance script
// either a same-scope sibling (canonical name) or a composition-
// delegated child script (leaf-name match; see composedLeafNames).
if (!scriptNames.Contains(call.TargetName)
&& !composedLeafNames.Contains(call.TargetName))
{
errors.Add(ValidationEntry.Error(ValidationCategory.CallTargetNotFound,
$"Script '{script.CanonicalName}' calls script '{call.TargetName}' which does not exist.",