From 450104a6ce744dcb947a218f038a86c8a606ad14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Wed, 3 Apr 2019 14:14:16 +0200 Subject: [PATCH] [NF] Fix Expression.typeOf for size(x). Belonging to [master]: - OpenModelica/OMCompiler#3033 --- Compiler/NFFrontEnd/NFExpression.mo | 2 +- Compiler/NFFrontEnd/NFType.mo | 13 +++++++++++++ Compiler/NFFrontEnd/NFTyping.mo | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) 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);