From 6abca0b5632b33c0d2e77da9105c918986dbf01d Mon Sep 17 00:00:00 2001 From: kabdelhak <38032125+kabdelhak@users.noreply.github.com> Date: Tue, 6 Feb 2024 08:54:33 +0100 Subject: [PATCH] [NB] update arrays of records lowering (#11956) - when lowering the children of record arrays inherit the array type dimensions to the children --- OMCompiler/Compiler/NFFrontEnd/NFVariable.mo | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo b/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo index 459bfe06b75..f4bbff1c8e4 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFVariable.mo @@ -35,6 +35,7 @@ encapsulated uniontype NFVariable import Class = NFClass; import Component = NFComponent; import ComponentRef = NFComponentRef; + import Dimension = NFDimension; import Expression = NFExpression; import NFInstNode.InstNode; import NFPrefixes.Visibility; @@ -204,10 +205,23 @@ public "Expands a variable into itself and its children if its complex." input Variable var; output list children; + protected + function expandChildType + "helper function to inherit the array type dimensions" + input output Variable child; + input list dimensions; + algorithm + child.ty := Type.liftArrayLeftList(child.ty, dimensions); + end expandChildType; algorithm - children := if (isComplex(var) or isComplexArray(var)) - then var :: List.flatten(list(expandChildren(v) for v in var.children)) - else {var}; + // for non-complex variables the children are empty therefore it will be returned itself + var.children := List.flatten(list(expandChildren(v) for v in var.children)); + if isComplexArray(var) then + // if the variable is an array, inherit the array dimensions + var.children := list(expandChildType(v, Type.arrayDims(var.ty)) for v in var.children); + end if; + // return all children and the variable itself + children := var :: var.children; end expandChildren; function typeOf