Skip to content

Commit f30c0ba

Browse files
committed
Type checking of divert targets being passed as arguments
1 parent ef41828 commit f30c0ba

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

compiler/ParsedHierarchy/Divert.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,25 @@ void CheckArgumentValidity()
318318
FlowBase.Argument flowArg = targetFlow.arguments [i];
319319
Parsed.Expression divArgExpr = arguments [i];
320320

321+
// Expecting a divert target as an argument, let's do some basic type checking
321322
if (flowArg.isDivertTarget) {
322-
if ( !(divArgExpr is VariableReference || divArgExpr is DivertTarget) ) {
323-
Error ("Target '"+targetFlow.name + "' expects a divert target for the parameter named -> " + flowArg.name + " but saw "+divArgExpr, divArgExpr);
323+
324+
// Not passing a divert target or any kind of variable reference?
325+
var varRef = divArgExpr as VariableReference;
326+
if (!(divArgExpr is DivertTarget) && varRef == null ) {
327+
Error ("Target '" + targetFlow.name + "' expects a divert target for the parameter named -> " + flowArg.name + " but saw " + divArgExpr, divArgExpr);
328+
}
329+
330+
// Passing 'a' instead of '-> a'?
331+
// i.e. read count instead of divert target
332+
else if (varRef != null) {
333+
334+
// Unfortunately have to manually resolve here since we're still in code gen
335+
var knotCountPath = new Path(varRef.path);
336+
Parsed.Object targetForCount = knotCountPath.ResolveFromContext (varRef);
337+
if (targetForCount != null) {
338+
Error ("Passing read count of '" + knotCountPath.dotSeparatedComponents + "' instead of a divert target. You probably meant '" + knotCountPath + "'");
339+
}
324340
}
325341
}
326342
}

0 commit comments

Comments
 (0)