Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit a4776a6

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix typing of calls with multiple outputs.
- 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]: - #2328 - OpenModelica/OpenModelica-testsuite#906
1 parent 72d39d6 commit a4776a6

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Compiler/NFFrontEnd/NFType.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ public
368368
end match;
369369
end isTuple;
370370

371+
function firstTupleType
372+
input Type ty;
373+
output Type outTy;
374+
algorithm
375+
outTy := match ty
376+
case TUPLE() then listHead(ty.types);
377+
else ty;
378+
end match;
379+
end firstTupleType;
380+
371381
function arrayElementType
372382
"Returns the common type of the elements in an array, or just the type
373383
itself if it's not an array type."

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ package ExpOrigin
133133
constant Type EQ_SUBEXPRESSION = intBitOr(EQUATION, SUBEXPRESSION);
134134
constant Type VALID_TYPENAME_SCOPE = intBitOr(ITERATION_RANGE, DIMENSION);
135135
constant Type DISCRETE_SCOPE = intBitOr(WHEN, intBitOr(INITIAL, FUNCTION));
136+
137+
function isSingleExpression
138+
"Returns true if the given origin indicates the expression is alone on
139+
either side of an equality/assignment."
140+
input Type origin;
141+
output Boolean isSingle = origin < ITERATION_RANGE - 1;
142+
end isSingleExpression;
136143
end ExpOrigin;
137144

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

11271134
case Expression.CALL()
1128-
then Call.typeCall(exp, origin, info);
1135+
algorithm
1136+
(e1, ty, var1) := Call.typeCall(exp, origin, info);
1137+
1138+
// If the call has multiple outputs and isn't alone on either side of an
1139+
// equation/algorithm, select the first output.
1140+
if Type.isTuple(ty) and not ExpOrigin.isSingleExpression(origin) then
1141+
ty := Type.firstTupleType(ty);
1142+
e1 := Expression.TUPLE_ELEMENT(e1, 1, ty);
1143+
end if;
1144+
then
1145+
(e1, ty, var1);
11291146

11301147
case Expression.CAST()
11311148
algorithm
@@ -1410,7 +1427,7 @@ algorithm
14101427

14111428
for s in subscripts loop
14121429
dim :: dims := dims;
1413-
(sub, var) := typeSubscript(s, dim, cref, i, origin, info);
1430+
(sub, var) := typeSubscript(s, dim, cref, i, next_origin, info);
14141431
typedSubs := sub :: typedSubs;
14151432
variability := Prefixes.variabilityMax(variability, var);
14161433
i := i + 1;

0 commit comments

Comments
 (0)