Skip to content

Commit 731cb1b

Browse files
committed
- Added check that the first argument to reinit is a subtype of Real.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11834 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 67041ce commit 731cb1b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Compiler/FrontEnd/InstSection.mo

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ algorithm
739739
case (cache,env,ih,mod,pre,csets,ci_state,SCode.EQ_REINIT(cref = cr,expReinit = e2,info = info),initial_,impl,graph)
740740
equation
741741
(cache,SOME((e1_1 as DAE.CREF(cr_1,t),tprop1,_))) = Static.elabCref(cache,env, cr, impl,false,pre,info) "reinit statement" ;
742+
checkReinitType(t, cr_1, info);
742743
(cache, e1_1, tprop1) = Ceval.cevalIfConstant(cache, env, e1_1, tprop1, impl, info);
743744
(cache,e2_1,tprop2,_) = Static.elabExp(cache,env, e2, impl,NONE(),true,pre,info);
744745
(cache, e2_1, tprop2) = Ceval.cevalIfConstant(cache, env, e2_1, tprop2, impl, info);
@@ -852,6 +853,37 @@ algorithm
852853
end matchcontinue;
853854
end instEquationCommonWork;
854855

856+
protected function checkReinitType
857+
"Checks that the base type of the given type is Real, otherwise it prints an
858+
error message that the first argument to reinit must be a subtype of Real."
859+
input DAE.Type inType;
860+
input DAE.ComponentRef inCref;
861+
input Absyn.Info inInfo;
862+
algorithm
863+
_ := matchcontinue(inType, inCref, inInfo)
864+
local
865+
DAE.Type ty;
866+
String cref_str;
867+
868+
case (_, _, _)
869+
equation
870+
ty = Types.arrayElementType(inType);
871+
true = Types.isReal(ty);
872+
then
873+
();
874+
875+
else
876+
equation
877+
cref_str = ComponentReference.printComponentRefStr(inCref);
878+
Error.addSourceMessage(Error.REINIT_MUST_BE_REAL,
879+
{cref_str}, inInfo);
880+
then
881+
fail();
882+
883+
end matchcontinue;
884+
end checkReinitType;
885+
886+
855887
/*protected function checkTupleCallEquation "Check if the two expressions make up a proper tuple function call.
856888
Returns the error on failure."
857889
input Absyn.Exp left;

Compiler/Util/Error.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ public constant Message FINAL_COMPONENT_OVERRIDE = MESSAGE(222, TRANSLATION(), E
591591
"Trying to override final component %s with modifier %s\n");
592592
public constant Message NOTIFY_NOT_LOADED = MESSAGE(223, SCRIPTING(), NOTIFICATION(),
593593
"Automatically loaded package %s %s due to uses annotation.");
594+
public constant Message REINIT_MUST_BE_REAL = MESSAGE(224, TRANSLATION(), ERROR(),
595+
"The first argument to reinit must be a subtype of Real in reinit of %s.");
594596

595597
public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(),
596598
"Parameter %s has neither value nor start value, and is fixed during initialization (fixed=true)");

0 commit comments

Comments
 (0)