Skip to content

Commit

Permalink
- Better error message for missing else in if-equations.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16054 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed May 15, 2013
1 parent 4be8414 commit 6cef107
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6544,14 +6544,27 @@ algorithm
list<String> strs;
String str,eqstr;
list<Integer> nrOfEquationsBranches;
case (_,_,_)

case (_, _, _)
equation
nrOfEquations = BackendEquation.equationLstSize(falseBranch);
nrOfEquationsBranches = List.map(trueBranches, BackendEquation.equationLstSize);
b = List.map1(nrOfEquationsBranches, intEq, nrOfEquations);
true = List.reduce(b,boolAnd);
then (nrOfEquations);
case (_,_,_)
then
nrOfEquations;

// An if-equation with non-parameter conditions must have an else-clause.
case (_, {}, _)
equation
Error.addSourceMessage(Error.IF_EQUATION_MISSING_ELSE, {},
DAEUtil.getElementSourceFileInfo(source));
then
fail();

// If if-equation with non-parameter conditions must have the same number of
// equations in each branch.
case (_, _ :: _, _)
equation
nrOfEquations = BackendEquation.equationLstSize(falseBranch);
nrOfEquationsBranches = List.map(trueBranches, BackendEquation.equationLstSize);
Expand All @@ -6560,7 +6573,9 @@ algorithm
str = stringDelimitList(strs,",");
str = "{" +& str +& "," +& intString(nrOfEquations) +& "}";
Error.addSourceMessage(Error.IF_EQUATION_UNBALANCED_2,{str,eqstr},DAEUtil.getElementSourceFileInfo(source));
then fail();
then
fail();

end matchcontinue;
end countEquationsInBranches;

Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ public constant Message IMPLICIT_ITERATOR_NOT_FOUND_IN_LOOP_BODY = MESSAGE(110,
Util.gettext("Identifier %s of implicit for iterator must be present as array subscript in the loop body."));
public constant Message IF_EQUATION_UNBALANCED = MESSAGE(114, TRANSLATION(), ERROR(),
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."));
public constant Message IF_EQUATION_MISSING_ELSE = MESSAGE(115, TRANSLATION(), ERROR(),
Util.gettext("Missing else-clause in if-equation with non-parameter conditions."));
public constant Message CONNECT_INCOMPATIBLE_TYPES = MESSAGE(117, TRANSLATION(), ERROR(),
Util.gettext("Incompatible components in connect statement: connect(%s, %s)\n- %s has components %s\n- %s has components %s"));
public constant Message CONNECT_OUTER_OUTER = MESSAGE(118, TRANSLATION(), ERROR(),
Expand Down

0 comments on commit 6cef107

Please sign in to comment.