diff --git a/Compiler/NFFrontEnd/NFExpression.mo b/Compiler/NFFrontEnd/NFExpression.mo index c4974826c6..a796e2003d 100644 --- a/Compiler/NFFrontEnd/NFExpression.mo +++ b/Compiler/NFFrontEnd/NFExpression.mo @@ -784,7 +784,7 @@ public case RECORD() then exp.ty; case CALL() then Call.typeOf(exp.call); case SIZE() then if isSome(exp.dimIndex) then - Type.INTEGER() else typeOf(exp.exp); + Type.INTEGER() else Type.sizeType(typeOf(exp.exp)); case END() then Type.INTEGER(); case BINARY() then Operator.typeOf(exp.operator); case UNARY() then Operator.typeOf(exp.operator); diff --git a/Compiler/NFFrontEnd/NFType.mo b/Compiler/NFFrontEnd/NFType.mo index 4beca48980..48c0cef591 100644 --- a/Compiler/NFFrontEnd/NFType.mo +++ b/Compiler/NFFrontEnd/NFType.mo @@ -892,5 +892,18 @@ public end match; end isBoxed; + function sizeType + input Type arrayTy; + output Type sizeTy; + algorithm + if Type.isUnknown(arrayTy) then + // Return unknown type if the type is unknown, to avoid returning Array[0] + // for untyped expressions. + sizeTy := Type.UNKNOWN(); + else + sizeTy := Type.ARRAY(Type.INTEGER(), {Dimension.fromInteger(dimensionCount(arrayTy))}); + end if; + end sizeType; + annotation(__OpenModelica_Interface="frontend"); end NFType; diff --git a/Compiler/NFFrontEnd/NFTyping.mo b/Compiler/NFFrontEnd/NFTyping.mo index 34ada10b5c..8f77582b0b 100644 --- a/Compiler/NFFrontEnd/NFTyping.mo +++ b/Compiler/NFFrontEnd/NFTyping.mo @@ -1892,7 +1892,7 @@ algorithm fail(); end if; - sizeType := Type.ARRAY(Type.INTEGER(), {Dimension.fromInteger(Type.dimensionCount(exp_ty))}); + sizeType := Type.sizeType(exp_ty); then (Expression.SIZE(exp, NONE()), sizeType, Variability.PARAMETER);