#2982 closed defect (fixed)
sorting of protected variable in a function
Reported by: | Willi Braun | Owned by: | Martin Sjölund |
---|---|---|---|
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 (9)
comment:1 by , 10 years ago
comment:2 by , 10 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 , 10 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 , 10 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 , 10 years ago
Description: | modified (diff) |
---|
comment:6 by , 10 years ago
We use the same sorting for non-functions is the problem here (to decide the order in which the components are ordered).
comment:7 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:8 by , 10 years ago
Component: | Run-time → Frontend |
---|---|
Milestone: | Future → 1.9.2 |
Resolution: | → fixed |
Status: | accepted → closed |
Fixed in r23351 (treating function context differently).
comment:9 by , 10 years ago
I'm really curious about the positive jump in the coverage tests, since I've just run 4 random ModelicaTest.Fluid examples and they all started to work.
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.