Skip to content

Commit

Permalink
Added warning when trying to apply non-array modification to array co…
Browse files Browse the repository at this point in the history
…mponent

without 'each'.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4715 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Dec 17, 2009
1 parent da92dc0 commit d62f92a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Compiler/Error.mo
Expand Up @@ -204,6 +204,7 @@ public constant ErrorID CONNECT_INCOMPATIBLE_TYPES=117;
public constant ErrorID CONNECT_OUTER_OUTER=118;
public constant ErrorID CONNECTOR_ARRAY_NONCONSTANT=119;
public constant ErrorID CONNECTOR_ARRAY_DIFFERENT=120;
public constant ErrorID MODIFIER_NON_ARRAY_TYPE_WARNING=121;

public constant ErrorID UNBOUND_PARAMETER_WARNING=500;
public constant ErrorID BUILTIN_FUNCTION_SUM_HAS_SCALAR_PARAMETER=501;
Expand Down Expand Up @@ -349,6 +350,8 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl

(CONNECTOR_ARRAY_DIFFERENT,TRANSLATION(),ERROR(),
"Unmatched dimension in equation connect(%s, %s)"),
(MODIFIER_NON_ARRAY_TYPE_WARNING,TRANSLATION(),WARNING(),
"Non-array modification '%s' for array component, possibly due to missing 'each'.\n"),
/*
(CONNECT_STREAM_TO_NONSTREAM,TRANSLATION(),ERROR(),
"Cannot connect stream component %s to non-stream component %s"),
Expand Down
15 changes: 15 additions & 0 deletions Compiler/Mod.mo
Expand Up @@ -1318,6 +1318,21 @@ algorithm
e = indexEqmod(SOME(DAE.TYPED(exp,NONE,DAE.PROP(t_1,c))), xs);
then
e;

case (e as SOME(DAE.TYPED(modifierAsExp = exp, properties = DAE.PROP(type_ = t))), _)
local
String exp_str;
equation
/* Trying to apply a non-array modifier to an array, which isn't
* really allowed but working anyway. Some standard Modelica libraries
* are missing the 'each' keyword though (i.e. the doublePendulum
* example), and therefore relying on this behaviour, so just print a
* warning here. */
failure(t_1 = Types.unliftArray(t));
exp_str = Exp.printExpStr(exp);
Error.addMessage(Error.MODIFIER_NON_ARRAY_TYPE_WARNING, {exp_str});
then fail();

case (SOME(eq),inIntegerLst) equation
true = RTOpts.debugFlag("failtrace");
Debug.fprintln("failtrace", "- Mod.indexEqmod failed for mod:\n " +&
Expand Down

0 comments on commit d62f92a

Please sign in to comment.