Skip to content

Commit

Permalink
Type checking of divert targets being passed as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
joethephish committed Apr 24, 2018
1 parent ef41828 commit f30c0ba
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions compiler/ParsedHierarchy/Divert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,25 @@ void CheckArgumentValidity()
FlowBase.Argument flowArg = targetFlow.arguments [i];
Parsed.Expression divArgExpr = arguments [i];

// Expecting a divert target as an argument, let's do some basic type checking
if (flowArg.isDivertTarget) {
if ( !(divArgExpr is VariableReference || divArgExpr is DivertTarget) ) {
Error ("Target '"+targetFlow.name + "' expects a divert target for the parameter named -> " + flowArg.name + " but saw "+divArgExpr, divArgExpr);

// Not passing a divert target or any kind of variable reference?
var varRef = divArgExpr as VariableReference;
if (!(divArgExpr is DivertTarget) && varRef == null ) {
Error ("Target '" + targetFlow.name + "' expects a divert target for the parameter named -> " + flowArg.name + " but saw " + divArgExpr, divArgExpr);
}

// Passing 'a' instead of '-> a'?
// i.e. read count instead of divert target
else if (varRef != null) {

// Unfortunately have to manually resolve here since we're still in code gen
var knotCountPath = new Path(varRef.path);
Parsed.Object targetForCount = knotCountPath.ResolveFromContext (varRef);
if (targetForCount != null) {
Error ("Passing read count of '" + knotCountPath.dotSeparatedComponents + "' instead of a divert target. You probably meant '" + knotCountPath + "'");
}
}
}
}
Expand Down

0 comments on commit f30c0ba

Please sign in to comment.