Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit adb7a38

Browse files
perostOpenModelica-Hudson
authored andcommitted
Fix handling of element redeclare condition.
- 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]: - #2237 - OpenModelica/OpenModelica-testsuite#862
1 parent 7a62703 commit adb7a38

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Compiler/FrontEnd/Inst.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,12 @@ algorithm
31753175
(el, _) := element;
31763176
(el_name, info) := InstUtil.extractCurrentName(el);
31773177

3178+
// An element redeclare may not have a condition.
3179+
if SCode.isElementRedeclare(el) then
3180+
Error.addSourceMessage(Error.REDECLARE_CONDITION, {el_name}, info);
3181+
fail();
3182+
end if;
3183+
31783184
(cond_val_opt, cache) :=
31793185
InstUtil.instElementCondExp(cache, env, el, prefix, info);
31803186

Compiler/Util/Error.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ public constant Message AMBIGUOUS_MATCHING_FUNCTIONS_NFINST = MESSAGE(323, TRANS
775775
Util.gettext("Ambiguous matching functions found for %s.\nCandidates are:\n %s"));
776776
public constant Message AMBIGUOUS_MATCHING_OPERATOR_FUNCTIONS_NFINST = MESSAGE(324, TRANSLATION(), ERROR(),
777777
Util.gettext("Ambiguous matching overloaded operator functions found for %s.\nCandidates are:\n %s"));
778+
public constant Message REDECLARE_CONDITION = MESSAGE(325, TRANSLATION(), ERROR(),
779+
Util.gettext("Invalid redeclaration of %s, a redeclare may not have a condition attribute."));
778780
public constant Message INITIALIZATION_NOT_FULLY_SPECIFIED = MESSAGE(496, TRANSLATION(), WARNING(),
779781
Util.gettext("The initial conditions are not fully specified. %s."));
780782
public constant Message INITIALIZATION_OVER_SPECIFIED = MESSAGE(497, TRANSLATION(), WARNING(),

Compiler/runtime/ErrorMessage.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ std::string ErrorMessage::getMessage_(int warningsAsErrors)
107107
message_.replace(str_pos, 2, *tok);
108108
str_pos += tok->size();
109109
*tok++;
110-
} else if(index_symbol >= '0' || index_symbol <= '9') {
110+
} else if(index_symbol >= '0' && index_symbol <= '9') {
111111
index = index_symbol - '0' - 1;
112112

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

120120
message_.replace(str_pos, 2, tokens_[index]);
121121
str_pos += tokens_[index].size();
122+
} else {
123+
++str_pos;
122124
}
123125
}
124126
veryshort_msg = message_;

0 commit comments

Comments
 (0)