Skip to content

Commit

Permalink
[NF] Fix subscripting of boxed/unboxed expressions.
Browse files Browse the repository at this point in the history
- Handle boxed types in Type.subscript.
- Add assertion in Type.subscript to catch unhandled types.
- Add special rules for unboxed/boxed values in
  Expression.applySubscript that subscripts the expressions they contain
  instead of creating unnecessary SUBSCRIPTED_EXPs.
  • Loading branch information
perost committed Jun 2, 2020
1 parent 1d9a583 commit 9837fec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 8 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -1039,6 +1039,14 @@ public
then bindingExpMap(exp,
function applySubscript(subscript = subscript, restSubscripts = restSubscripts));

case UNBOX()
algorithm
outExp := applySubscript(subscript, exp.exp, restSubscripts);
then
unbox(outExp);

case BOX() then BOX(applySubscript(subscript, exp.exp, restSubscripts));

else makeSubscriptedExp(subscript :: restSubscripts, exp);
end match;
end applySubscript;
Expand Down
11 changes: 9 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -1025,8 +1025,15 @@ public
subscript(ty.falseType, subs),
ty.matchedBranch);

case UNKNOWN()
then ty;
case METABOXED() then METABOXED(subscript(ty.ty, subs));
case UNKNOWN() then ty;

else
algorithm
Error.assertion(false, getInstanceName() +
" got unsubscriptable type " + toString(ty) + "\n", sourceInfo());
then
fail();

end match;
end subscript;
Expand Down

0 comments on commit 9837fec

Please sign in to comment.