Skip to content

Commit 0f1ee9a

Browse files
authored
Fix Flatten.splitRecordCref (#12181)
- Only mark the condition of an if-expression as structural if it could actually be evaluated.
1 parent a7d11a8 commit 0f1ee9a

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,11 @@ algorithm
10031003
guard Expression.variability(outExp.condition) <= Variability.PARAMETER
10041004
algorithm
10051005
cond := Ceval.tryEvalExp(outExp.condition);
1006-
Structural.markExp(outExp.condition);
1006+
1007+
// Only mark the condition as structural if it could be evaluated.
1008+
if not referenceEq(cond, outExp.condition) then
1009+
Structural.markExp(outExp.condition);
1010+
end if;
10071011
then
10081012
match cond
10091013
case Expression.BOOLEAN() then splitRecordCref(if cond.value then outExp.trueBranch else outExp.falseBranch);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// name: CevalBinding9
2+
// status: correct
3+
// cflags: -d=newInst
4+
//
5+
//
6+
7+
pure function ext_fun
8+
input Real u1;
9+
output Real y;
10+
external "C";
11+
end ext_fun;
12+
13+
model Pump
14+
parameter Real m_flow_nominal;
15+
parameter Integer nOri = 2;
16+
parameter Real V_flow = 2.0*m_flow_nominal;
17+
final parameter power pow = if V_flow < 0 then power(V_flow=1) else power(V_flow=2);
18+
end Pump;
19+
20+
record power
21+
parameter Real V_flow = 0;
22+
end power;
23+
24+
model CevalBinding9
25+
Pump pumHeaPum(m_flow_nominal = Q);
26+
parameter Real T = 0;
27+
parameter Real Q = ext_fun(T);
28+
end CevalBinding9;
29+
30+
// Result:
31+
// function ext_fun
32+
// input Real u1;
33+
// output Real y;
34+
//
35+
// external "C" y = ext_fun(u1);
36+
// end ext_fun;
37+
//
38+
// function power "Automatically generated record constructor for power"
39+
// input Real V_flow = 0.0;
40+
// output power res;
41+
// end power;
42+
//
43+
// class CevalBinding9
44+
// parameter Real pumHeaPum.m_flow_nominal = Q;
45+
// parameter Integer pumHeaPum.nOri = 2;
46+
// parameter Real pumHeaPum.V_flow = 2.0 * pumHeaPum.m_flow_nominal;
47+
// final parameter Real pumHeaPum.pow.V_flow(fixed = false);
48+
// parameter Real T = 0.0;
49+
// parameter Real Q = ext_fun(T);
50+
// initial equation
51+
// pumHeaPum.pow = if pumHeaPum.V_flow < 0.0 then power(1.0) else power(2.0);
52+
// end CevalBinding9;
53+
// endResult

testsuite/flattening/modelica/scodeinst/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ CevalBinding5.mo \
126126
CevalBinding6.mo \
127127
CevalBinding7.mo \
128128
CevalBinding8.mo \
129+
CevalBinding9.mo \
129130
CevalConstant1.mo \
130131
CevalCeil1.mo \
131132
CevalCos1.mo \

0 commit comments

Comments
 (0)