diff --git a/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo b/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo index 892e73ece96..0885a496971 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo @@ -180,6 +180,16 @@ public end match; end isIterator; + function isInput + input ComponentRef cref; + output Boolean res; + algorithm + res := match cref + case CREF() then InstNode.isInput(cref.node); + else false; + end match; + end isInput; + function node input ComponentRef cref; output InstNode node; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFExpression.mo b/OMCompiler/Compiler/NFFrontEnd/NFExpression.mo index 12189c1678d..f6d95bbf7ee 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFExpression.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFExpression.mo @@ -282,6 +282,16 @@ public end match; end isCref; + function isFunctionInputCref + input Expression exp; + output Boolean res; + algorithm + res := match exp + case CREF() then ComponentRef.isInput(ComponentRef.last(exp.cref)); + else false; + end match; + end isFunctionInputCref; + function isWildCref input Expression exp; output Boolean wild; diff --git a/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo b/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo index 3468f4ce80d..9ed7785a9b6 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFTyping.mo @@ -612,7 +612,8 @@ algorithm end if; else // For functions, only evaluate constant and structural parameter expressions. - if var <= Variability.STRUCTURAL_PARAMETER then + if var <= Variability.STRUCTURAL_PARAMETER and + not Expression.contains(exp, Expression.isFunctionInputCref) then exp := Ceval.tryEvalExp(exp); end if; end if; diff --git a/testsuite/flattening/modelica/scodeinst/FunctionRecordArg5.mo b/testsuite/flattening/modelica/scodeinst/FunctionRecordArg5.mo new file mode 100644 index 00000000000..9729aeaf253 --- /dev/null +++ b/testsuite/flattening/modelica/scodeinst/FunctionRecordArg5.mo @@ -0,0 +1,58 @@ +// name: FunctionRecordArg5 +// keywords: +// status: correct +// cflags: -d=newInst +// + +model FunctionRecordArg5 + record BaseRecord + constant Integer nx = 4; + end BaseRecord; + + record ExtendRecord + extends BaseRecord(nx=6); + end ExtendRecord; + + function initArr + input BaseRecord r = ExtendRecord(); + output Real x_1; + protected + Real x[r.nx-1]; + algorithm + x := zeros(r.nx - 1); + x_1 := x[1]; + end initArr; + + BaseRecord r = ExtendRecord(); + Real x_1; +equation + x_1 = initArr(r); +end FunctionRecordArg5; + +// Result: +// function FunctionRecordArg5.BaseRecord "Automatically generated record constructor for FunctionRecordArg5.BaseRecord" +// input Integer nx = 4; +// output BaseRecord res; +// end FunctionRecordArg5.BaseRecord; +// +// function FunctionRecordArg5.ExtendRecord "Automatically generated record constructor for FunctionRecordArg5.ExtendRecord" +// input Integer nx = 6; +// output ExtendRecord res; +// end FunctionRecordArg5.ExtendRecord; +// +// function FunctionRecordArg5.initArr +// input FunctionRecordArg5.BaseRecord r = FunctionRecordArg5.ExtendRecord(6); +// output Real x_1; +// protected Real[r.nx - 1] x; +// algorithm +// x := fill(0.0, r.nx - 1); +// x_1 := x[1]; +// end FunctionRecordArg5.initArr; +// +// class FunctionRecordArg5 +// constant Integer r.nx = 6; +// Real x_1; +// equation +// x_1 = FunctionRecordArg5.initArr(r); +// end FunctionRecordArg5; +// endResult diff --git a/testsuite/flattening/modelica/scodeinst/Makefile b/testsuite/flattening/modelica/scodeinst/Makefile index 30101ed7385..00aa8efef52 100644 --- a/testsuite/flattening/modelica/scodeinst/Makefile +++ b/testsuite/flattening/modelica/scodeinst/Makefile @@ -652,6 +652,7 @@ FunctionRecordArg1.mo \ FunctionRecordArg2.mo \ FunctionRecordArg3.mo \ FunctionRecordArg4.mo \ +FunctionRecordArg5.mo \ FunctionRecursive1.mo \ FunctionRecursive2.mo \ FunctionSections1.mo \