Skip to content

Commit

Permalink
Fix handling of element redeclare condition.
Browse files Browse the repository at this point in the history
- Add error message when an element redeclare includes a condition.
- Fix the sanity check for positional argument indices in the error
  message handling code.

Belonging to [master]:
  - OpenModelica/OMCompiler#2237
  - OpenModelica/OpenModelica-testsuite#862
  • Loading branch information
perost authored and OpenModelica-Hudson committed Feb 26, 2018
1 parent 7a62703 commit adb7a38
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -3175,6 +3175,12 @@ algorithm
(el, _) := element;
(el_name, info) := InstUtil.extractCurrentName(el);

// An element redeclare may not have a condition.
if SCode.isElementRedeclare(el) then
Error.addSourceMessage(Error.REDECLARE_CONDITION, {el_name}, info);
fail();
end if;

(cond_val_opt, cache) :=
InstUtil.instElementCondExp(cache, env, el, prefix, info);

Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -775,6 +775,8 @@ public constant Message AMBIGUOUS_MATCHING_FUNCTIONS_NFINST = MESSAGE(323, TRANS
Util.gettext("Ambiguous matching functions found for %s.\nCandidates are:\n %s"));
public constant Message AMBIGUOUS_MATCHING_OPERATOR_FUNCTIONS_NFINST = MESSAGE(324, TRANSLATION(), ERROR(),
Util.gettext("Ambiguous matching overloaded operator functions found for %s.\nCandidates are:\n %s"));
public constant Message REDECLARE_CONDITION = MESSAGE(325, TRANSLATION(), ERROR(),
Util.gettext("Invalid redeclaration of %s, a redeclare may not have a condition attribute."));
public constant Message INITIALIZATION_NOT_FULLY_SPECIFIED = MESSAGE(496, TRANSLATION(), WARNING(),
Util.gettext("The initial conditions are not fully specified. %s."));
public constant Message INITIALIZATION_OVER_SPECIFIED = MESSAGE(497, TRANSLATION(), WARNING(),
Expand Down
4 changes: 3 additions & 1 deletion Compiler/runtime/ErrorMessage.cpp
Expand Up @@ -107,7 +107,7 @@ std::string ErrorMessage::getMessage_(int warningsAsErrors)
message_.replace(str_pos, 2, *tok);
str_pos += tok->size();
*tok++;
} else if(index_symbol >= '0' || index_symbol <= '9') {
} else if(index_symbol >= '0' && index_symbol <= '9') {
index = index_symbol - '0' - 1;

if(index >= tokens_.size() || index < 0) {
Expand All @@ -119,6 +119,8 @@ std::string ErrorMessage::getMessage_(int warningsAsErrors)

message_.replace(str_pos, 2, tokens_[index]);
str_pos += tokens_[index].size();
} else {
++str_pos;
}
}
veryshort_msg = message_;
Expand Down

0 comments on commit adb7a38

Please sign in to comment.