Skip to content

Commit

Permalink
[NF] Fix typing of calls with multiple outputs.
Browse files Browse the repository at this point in the history
- Fix typing of function calls with multiple outputs so that only the
  first output is used when the call isn't alone on the rhs.
- Use correct origin in Typing.typeSubscripts.

Belonging to [master]:
  - OpenModelica/OMCompiler#2328
  - OpenModelica/OpenModelica-testsuite#906
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 28, 2018
1 parent 72d39d6 commit a4776a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -368,6 +368,16 @@ public
end match;
end isTuple;

function firstTupleType
input Type ty;
output Type outTy;
algorithm
outTy := match ty
case TUPLE() then listHead(ty.types);
else ty;
end match;
end firstTupleType;

function arrayElementType
"Returns the common type of the elements in an array, or just the type
itself if it's not an array type."
Expand Down
21 changes: 19 additions & 2 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -133,6 +133,13 @@ package ExpOrigin
constant Type EQ_SUBEXPRESSION = intBitOr(EQUATION, SUBEXPRESSION);
constant Type VALID_TYPENAME_SCOPE = intBitOr(ITERATION_RANGE, DIMENSION);
constant Type DISCRETE_SCOPE = intBitOr(WHEN, intBitOr(INITIAL, FUNCTION));

function isSingleExpression
"Returns true if the given origin indicates the expression is alone on
either side of an equality/assignment."
input Type origin;
output Boolean isSingle = origin < ITERATION_RANGE - 1;
end isSingleExpression;
end ExpOrigin;

public
Expand Down Expand Up @@ -1125,7 +1132,17 @@ algorithm
TypeCheck.checkIfExpression(e1, ty1, var1, e2, ty2, var2, e3, ty3, var3, info);

case Expression.CALL()
then Call.typeCall(exp, origin, info);
algorithm
(e1, ty, var1) := Call.typeCall(exp, origin, info);

// If the call has multiple outputs and isn't alone on either side of an
// equation/algorithm, select the first output.
if Type.isTuple(ty) and not ExpOrigin.isSingleExpression(origin) then
ty := Type.firstTupleType(ty);
e1 := Expression.TUPLE_ELEMENT(e1, 1, ty);
end if;
then
(e1, ty, var1);

case Expression.CAST()
algorithm
Expand Down Expand Up @@ -1410,7 +1427,7 @@ algorithm

for s in subscripts loop
dim :: dims := dims;
(sub, var) := typeSubscript(s, dim, cref, i, origin, info);
(sub, var) := typeSubscript(s, dim, cref, i, next_origin, info);
typedSubs := sub :: typedSubs;
variability := Prefixes.variabilityMax(variability, var);
i := i + 1;
Expand Down

0 comments on commit a4776a6

Please sign in to comment.