Skip to content

Commit b3374e0

Browse files
committed
Fix evaluation of end in functions
- Include the scope when looking for replacements in EvalFunction, to fix the case where a record field might have a dimension that gets prefixed with its scope and then used to replace `end` inside a function.
1 parent 87c68de commit b3374e0

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

OMCompiler/Compiler/NFFrontEnd/NFEvalFunction.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ protected
468468
InstNode parent, node;
469469
algorithm
470470
// Explode the cref into a list of parts in reverse order.
471-
cref_parts := ComponentRef.toListReverse(cref, includeScope = false);
471+
cref_parts := ComponentRef.toListReverse(cref, includeScope = true);
472472

473473
// If the list is empty it's probably an iterator or _, which shouldn't be replaced.
474474
if listEmpty(cref_parts) then
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// name: FunctionRecordArg7
2+
// keywords:
3+
// status: correct
4+
//
5+
6+
record flowParametersInternal
7+
parameter Integer n annotation(Evaluate = true);
8+
parameter Real V_flow[n];
9+
end flowParametersInternal;
10+
11+
function power
12+
input flowParametersInternal pressure;
13+
output Real power[11];
14+
algorithm
15+
power := {pressure.V_flow[end]*i for i in 0:10};
16+
end power;
17+
18+
model FunctionRecordArg7
19+
parameter flowParametersInternal pCur1(n = 3, V_flow = ones(3));
20+
parameter Real powEu_internal[:] = power(pressure = pCur1);
21+
annotation(__OpenModelica_commandLineOptions="-d=evaluateAllParameters");
22+
end FunctionRecordArg7;
23+
24+
// Result:
25+
// class FunctionRecordArg7
26+
// final parameter Integer pCur1.n = 3;
27+
// final parameter Real pCur1.V_flow[1] = 1.0;
28+
// final parameter Real pCur1.V_flow[2] = 1.0;
29+
// final parameter Real pCur1.V_flow[3] = 1.0;
30+
// final parameter Real powEu_internal[1] = 0.0;
31+
// final parameter Real powEu_internal[2] = 1.0;
32+
// final parameter Real powEu_internal[3] = 2.0;
33+
// final parameter Real powEu_internal[4] = 3.0;
34+
// final parameter Real powEu_internal[5] = 4.0;
35+
// final parameter Real powEu_internal[6] = 5.0;
36+
// final parameter Real powEu_internal[7] = 6.0;
37+
// final parameter Real powEu_internal[8] = 7.0;
38+
// final parameter Real powEu_internal[9] = 8.0;
39+
// final parameter Real powEu_internal[10] = 9.0;
40+
// final parameter Real powEu_internal[11] = 10.0;
41+
// end FunctionRecordArg7;
42+
// endResult

testsuite/flattening/modelica/scodeinst/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ FunctionRecordArg3.mo \
713713
FunctionRecordArg4.mo \
714714
FunctionRecordArg5.mo \
715715
FunctionRecordArg6.mo \
716+
FunctionRecordArg7.mo \
716717
FunctionRecursive1.mo \
717718
FunctionRecursive2.mo \
718719
FunctionSections1.mo \

0 commit comments

Comments
 (0)