diff --git a/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo b/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo index 20dabf291fe..df321b0ac90 100644 --- a/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo +++ b/OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo @@ -2638,16 +2638,16 @@ algorithm Discrete output variables that do not occur get computed by pre(). Ticket #5659 */ - if indexTypeSovable(inIndexType) then - try - crefLst := CheckModel.algorithmStatementListOutputs(statementLst, DAE.EXPAND()); // expand as we're in an algorithm - for cr in crefLst loop + if indexTypeSolvable(inIndexType) then + crefLst := CheckModel.algorithmStatementListOutputs(statementLst, DAE.EXPAND()); // expand as we're in an algorithm + for cr in crefLst loop + try (varslst, p) := BackendVariable.getVar(cr, vars); - res := incidenceRowExp1Discrete(varslst,p,res,0); - end for; - else - /* ... */ - end try; + res := incidenceRowExp1Discrete(varslst, p, res); + else + /* Nothing to do, BackendVariable.getVar fails for $START, $PRE, time etc. */ + end try; + end for; end if; then (res,size); @@ -3258,21 +3258,21 @@ protected function incidenceRowExp1Discrete input list inVarLst; input list inIntegerLst; input AvlSetInt.Tree inVarIndxLst; - input Integer diffindex; output AvlSetInt.Tree outVarIndxLst; algorithm - outVarIndxLst := match (inVarLst,inIntegerLst,inVarIndxLst,diffindex) + outVarIndxLst := match (inVarLst,inIntegerLst) local list rest; list irest; AvlSetInt.Tree vars; - Integer i,i1,diffidx; - Boolean b; - case ({},{},vars,_) then vars; - case (BackendDAE.VAR(varKind = BackendDAE.DISCRETE())::rest,i::irest,_,_) + Integer i; + case ({}, {}) then inVarIndxLst; + case (BackendDAE.VAR(varKind = BackendDAE.DISCRETE())::rest, i::irest) equation vars = AvlSetInt.add(inVarIndxLst, i); - then incidenceRowExp1Discrete(rest,irest,vars,diffindex); + then incidenceRowExp1Discrete(rest,irest,vars); + case (_::rest, _::irest) + then incidenceRowExp1Discrete(rest,irest,inVarIndxLst); end match; end incidenceRowExp1Discrete; @@ -9958,7 +9958,7 @@ algorithm end match; end containsHomotopyCall2; -protected function indexTypeSovable +protected function indexTypeSolvable input BackendDAE.IndexType indexType; output Boolean b; algorithm @@ -9966,7 +9966,7 @@ algorithm case BackendDAE.SOLVABLE() then true; else false; end match; -end indexTypeSovable; +end indexTypeSolvable; annotation(__OpenModelica_Interface="backend"); end BackendDAEUtil; diff --git a/testsuite/simulation/modelica/algorithms_functions/Makefile b/testsuite/simulation/modelica/algorithms_functions/Makefile index 0770ecfacfb..c9f7597f5d1 100644 --- a/testsuite/simulation/modelica/algorithms_functions/Makefile +++ b/testsuite/simulation/modelica/algorithms_functions/Makefile @@ -15,6 +15,7 @@ bug_2271.mos \ bug_2286.mos \ bug_2286_literal.mos \ bug2888.mos \ +bug_5659.mos \ ComplexSystem.mos \ DoubleWhenSequential.mos \ ForIterator1.mos \ diff --git a/testsuite/simulation/modelica/algorithms_functions/bug_5659.mos b/testsuite/simulation/modelica/algorithms_functions/bug_5659.mos new file mode 100644 index 00000000000..7afc653ecad --- /dev/null +++ b/testsuite/simulation/modelica/algorithms_functions/bug_5659.mos @@ -0,0 +1,37 @@ +// name: bug_5659 +// keywords: +// status: correct +// teardown_command: rm -rf bug_5659_* _bug_5659_* output.log +// +// tests for counting of algorithm section output variables involving +// arrays and records combined. +// + +loadString(" +/*slightly altered ticket model. +https://trac.openmodelica.org/OpenModelica/ticket/5659 +*/ +model bug_5659 + discrete Real x; + discrete Real[2] data; + Real y; +algorithm + x := 1; + when sample(0, 0.1) then + data[1] := time; + end when; + y := cos(time); +end bug_5659; +"); getErrorString(); + +// bug_5659 has 4 equation(s) and 4 variable(s) +checkModel(bug_5659); getErrorString(); + +// Result: +// true +// "" +// "Check of bug_5659 completed successfully. +// Class bug_5659 has 4 equation(s) and 4 variable(s). +// 0 of these are trivial equation(s)." +// "" +// endResult