Skip to content

Commit 450104a

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix Expression.typeOf for size(x).
Belonging to [master]: - OpenModelica/OMCompiler#3033
1 parent 8676697 commit 450104a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ public
784784
case RECORD() then exp.ty;
785785
case CALL() then Call.typeOf(exp.call);
786786
case SIZE() then if isSome(exp.dimIndex) then
787-
Type.INTEGER() else typeOf(exp.exp);
787+
Type.INTEGER() else Type.sizeType(typeOf(exp.exp));
788788
case END() then Type.INTEGER();
789789
case BINARY() then Operator.typeOf(exp.operator);
790790
case UNARY() then Operator.typeOf(exp.operator);

Compiler/NFFrontEnd/NFType.mo

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,5 +892,18 @@ public
892892
end match;
893893
end isBoxed;
894894

895+
function sizeType
896+
input Type arrayTy;
897+
output Type sizeTy;
898+
algorithm
899+
if Type.isUnknown(arrayTy) then
900+
// Return unknown type if the type is unknown, to avoid returning Array[0]
901+
// for untyped expressions.
902+
sizeTy := Type.UNKNOWN();
903+
else
904+
sizeTy := Type.ARRAY(Type.INTEGER(), {Dimension.fromInteger(dimensionCount(arrayTy))});
905+
end if;
906+
end sizeType;
907+
895908
annotation(__OpenModelica_Interface="frontend");
896909
end NFType;

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ algorithm
18921892
fail();
18931893
end if;
18941894

1895-
sizeType := Type.ARRAY(Type.INTEGER(), {Dimension.fromInteger(Type.dimensionCount(exp_ty))});
1895+
sizeType := Type.sizeType(exp_ty);
18961896
then
18971897
(Expression.SIZE(exp, NONE()), sizeType, Variability.PARAMETER);
18981898

0 commit comments

Comments
 (0)