Opened 11 years ago
Last modified 11 years ago
#2982 closed defect
sorting of protected variable in a function — at Version 5
| Reported by: | Willi Braun | Owned by: | somebody |
|---|---|---|---|
| Priority: | high | Milestone: | 1.9.2 |
| Component: | Frontend | Version: | trunk |
| Keywords: | Cc: | Martin Sjölund |
Description (last modified by )
Following model fail due to using not initialized memory:
ModelicaTest.Fluid.Dissipation.Verifications.HeatTransfer.StraightPipe.kc_overall_KC
It seems that we sort the protected variables in a function wrong or actually we don't sort them at all, if there is an if-expression involved.
loadString("
function f
input Real x;
output Real y;
protected
Real a = sin(x);
Real b = if x > 0 then cos(c) else sin(c);
Real c = cos(a);
algorithm
y := c;
end f;
model A
Real x(start=1);
equation
der(x) = f(x);
end A;
"); getErrorString();
simulate(A); getErrorString();
Where is this sorting performed?
Change History (5)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Since praying seems not to help. Why can't we just consider all branches as we do it for the ordinary matching?
comment:3 by , 11 years ago
Because... HeatingSystem.mo Error: Variable tank: Cyclically dependent constants or parameters found in scope Modelica.Fluid.Vessels.OpenTank$tank:
- parameter Medium.SpecificEnthalpy h_start = if use_T_start then Medium.specificEnthalpy_pTX(p_start, T_start, X_start) else Medium.h_default
- parameter Medium.Temperature T_start = if use_T_start then system.T_start else Medium.temperature_phX(p_start, h_start, X_start)
comment:4 by , 11 years ago
Okay, but this is cycle in non-input bindings and this is illegal, as far as I understand the Modelica Spec.
Modelica Spec:
12.4.4: Initialization and Declaration Assignments of Components in Functions
[...]These bindings must be executed in an order where a variable is not used before its declaration assignment has been executed; it is an error if no such order exists (i.e. the binding must be acyclic). [...]
comment:5 by , 11 years ago
| Description: | modified (diff) |
|---|

I assume this part in InstUtil.mo:
I just searched for calls to Graph.topologicalSort. Maybe we either remove that case, or we ignore that case for function scope.