Skip to content

Commit

Permalink
Fix bug #1303
Browse files Browse the repository at this point in the history
- Bugfix for Inst.checkRecursiveDefinition
  - We now check if the class we looked up is the same as the actual class, instead of just comparing the last identifier (this should also successfully guard against renaming imports/etc)
  - Added testcase NotDependsRecursive.mo


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6323 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 9, 2010
1 parent e45d521 commit 30548eb
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions Compiler/Inst.mo
Expand Up @@ -5772,7 +5772,7 @@ algorithm
env_1 = env;
(cache,cl,cenv) = Lookup.lookupClass(cache, env_1, t, true);

checkRecursiveDefinition(env,t,ci_state,cl);
checkRecursiveDefinition(env,cenv,ci_state,cl);

//If the element is `protected\', and an external modification
//is applied, it is an error.
Expand Down Expand Up @@ -6076,36 +6076,43 @@ protected function checkRecursiveDefinition
"Checks that a class does not have a recursive definition,
i.e. an instance of itself. This is not allowed in Modelica."
input Env.Env env;
input Absyn.Path tp;
input Env.Env cenv;
input ClassInf.State ci_state;
input SCode.Class cl;
algorithm
_ := matchcontinue(env,tp,ci_state,cl)
local Absyn.Path envPath;
_ := matchcontinue(env,cenv,ci_state,cl)
local
Absyn.Path envPath,cenvPath;
String name,s;
// No envpath, nothing to check.
case(env,tp,ci_state,cl)
case(env,cenv,ci_state,cl)
equation
NONE = Env.getEnvPath(env);
then ();
// No recursive definition, succed.
case(env,tp,ci_state,cl)
// No recursive definition, succeed.
case(env,cenv,ci_state,SCode.CLASS(name=name))
equation
envPath = Env.getEnvName(env);
cenvPath = Env.getEnvName(Env.openScope(cenv,false,SOME(name),NONE()));
false = Absyn.pathEqual(envPath,cenvPath);
then ();
// No recursive definition, succeed.
case(env,cenv,ci_state,cl)
equation
SOME(envPath) = Env.getEnvPath(env);
false = Absyn.pathSuffixOf(tp,envPath) and checkRecursiveDefinitionRecConst(ci_state,cl);
false = checkRecursiveDefinitionRecConst(ci_state,cl);
then ();
// report error: recursive definition
case(env,tp,ci_state,cl) local String s;
case(env,cenv,ci_state,SCode.CLASS(name=name))
equation
SOME(envPath) = Env.getEnvPath(env);
true= Absyn.pathSuffixOf(tp,envPath);
s = Absyn.pathString(tp);
cenvPath = Env.getEnvName(Env.openScope(cenv,false,SOME(name),NONE()));
s = Absyn.pathString(cenvPath);
Error.addMessage(Error.RECURSIVE_DEFINITION,{s});
then fail();
// failure
case(env,tp,ci_state,cl)
case(env,_,ci_state,cl)
equation
true = RTOpts.debugFlag("failtrace");
Debug.fprint("failtrace","-Inst.checkRecursiveDefinition failed, envpath="+&Env.printEnvPathStr(env)+&" tp :"+&Absyn.pathString(tp)+&"\n");
Debug.fprint("failtrace","-Inst.checkRecursiveDefinition failed, envpath="+&Env.printEnvPathStr(env)+&"\n");
then fail();
end matchcontinue;
end checkRecursiveDefinition;
Expand Down

0 comments on commit 30548eb

Please sign in to comment.