Skip to content

Commit 6cef107

Browse files
committed
- Better error message for missing else in if-equations.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16054 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 4be8414 commit 6cef107

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6544,14 +6544,27 @@ algorithm
65446544
list<String> strs;
65456545
String str,eqstr;
65466546
list<Integer> nrOfEquationsBranches;
6547-
case (_,_,_)
6547+
6548+
case (_, _, _)
65486549
equation
65496550
nrOfEquations = BackendEquation.equationLstSize(falseBranch);
65506551
nrOfEquationsBranches = List.map(trueBranches, BackendEquation.equationLstSize);
65516552
b = List.map1(nrOfEquationsBranches, intEq, nrOfEquations);
65526553
true = List.reduce(b,boolAnd);
6553-
then (nrOfEquations);
6554-
case (_,_,_)
6554+
then
6555+
nrOfEquations;
6556+
6557+
// An if-equation with non-parameter conditions must have an else-clause.
6558+
case (_, {}, _)
6559+
equation
6560+
Error.addSourceMessage(Error.IF_EQUATION_MISSING_ELSE, {},
6561+
DAEUtil.getElementSourceFileInfo(source));
6562+
then
6563+
fail();
6564+
6565+
// If if-equation with non-parameter conditions must have the same number of
6566+
// equations in each branch.
6567+
case (_, _ :: _, _)
65556568
equation
65566569
nrOfEquations = BackendEquation.equationLstSize(falseBranch);
65576570
nrOfEquationsBranches = List.map(trueBranches, BackendEquation.equationLstSize);
@@ -6560,7 +6573,9 @@ algorithm
65606573
str = stringDelimitList(strs,",");
65616574
str = "{" +& str +& "," +& intString(nrOfEquations) +& "}";
65626575
Error.addSourceMessage(Error.IF_EQUATION_UNBALANCED_2,{str,eqstr},DAEUtil.getElementSourceFileInfo(source));
6563-
then fail();
6576+
then
6577+
fail();
6578+
65646579
end matchcontinue;
65656580
end countEquationsInBranches;
65666581

Compiler/Util/Error.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ public constant Message IMPLICIT_ITERATOR_NOT_FOUND_IN_LOOP_BODY = MESSAGE(110,
333333
Util.gettext("Identifier %s of implicit for iterator must be present as array subscript in the loop body."));
334334
public constant Message IF_EQUATION_UNBALANCED = MESSAGE(114, TRANSLATION(), ERROR(),
335335
Util.gettext("In equation %s. If-equation with conditions that are not parameter expressions must have the same number of equations in each branch, equation count is %s for each respective branch."));
336+
public constant Message IF_EQUATION_MISSING_ELSE = MESSAGE(115, TRANSLATION(), ERROR(),
337+
Util.gettext("Missing else-clause in if-equation with non-parameter conditions."));
336338
public constant Message CONNECT_INCOMPATIBLE_TYPES = MESSAGE(117, TRANSLATION(), ERROR(),
337339
Util.gettext("Incompatible components in connect statement: connect(%s, %s)\n- %s has components %s\n- %s has components %s"));
338340
public constant Message CONNECT_OUTER_OUTER = MESSAGE(118, TRANSLATION(), ERROR(),

0 commit comments

Comments
 (0)