Skip to content

Commit

Permalink
Added a check whether component's name is the same as its type specif…
Browse files Browse the repository at this point in the history
…ier. Modified the testsuite correspondingly. Added a couple more test cases.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6197 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Alexey Lebedev committed Sep 23, 2010
1 parent 6b970d4 commit d73eb81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Compiler/Error.mo
Expand Up @@ -220,6 +220,7 @@ public constant ErrorID IF_EQUATION_UNBALANCED_2=132;
public constant ErrorID EQUATION_GENERIC_FAILURE=133;
public constant ErrorID INST_PARTIAL_CLASS_CHECK_MODEL_WARNING=134; // adrpo: legal to instantiate a partial class when we run checkModel
public constant ErrorID VARIABLE_BINDING_TYPE_MISMATCH=135;
public constant ErrorID COMPONENT_NAME_SAME_AS_TYPE_NAME=136;


public constant ErrorID UNBOUND_PARAMETER_WITH_START_VALUE_WARNING=499;
Expand Down Expand Up @@ -572,7 +573,8 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(META_POLYMORPHIC, TRANSLATION(),ERROR(), " %s uses invalid subtypeof syntax. Only subtypeof Any is supported."),
(META_FUNCTION_TYPE_NO_PARTIAL_PREFIX, TRANSLATION(),ERROR(), "%s is used as a function reference, but doesn't specify the partial prefix."),
(IF_EQUATION_WARNING,SYMBOLIC(),WARNING(), "If-equations are only partially supported. Ignoring%s"),
(EQUATION_GENERIC_FAILURE,TRANSLATION(),ERROR(),"Failed to instantiate equation %s")
(EQUATION_GENERIC_FAILURE,TRANSLATION(),ERROR(),"Failed to instantiate equation %s"),
(COMPONENT_NAME_SAME_AS_TYPE_NAME,GRAMMAR(),WARNING(),"Component %s has the same name as its type %s . This is forbidden by Modelica specifications and may lead to lookup error")

};

Expand Down
13 changes: 13 additions & 0 deletions Compiler/Inst.mo
Expand Up @@ -5606,6 +5606,17 @@ algorithm
then
(cache,env_1,ih,store,dae,csets,ci_state,{},graph);

// Check if component's name is the same as its type's name
case (cache,env,ih,store,mods,pre,csets,ci_state,
((comp as SCode.COMPONENT(component = n,typeSpec = ( ts as Absyn.TPATH(t, _)))),cmod), inst_dims,impl,graph)
equation
true = stringEqual(n, Absyn.pathLastIdent(t));
ns = Absyn.pathString(t);
Error.addMessage(Error.COMPONENT_NAME_SAME_AS_TYPE_NAME, {n,ns});
then
fail();


// A component
// This is the rule for instantiating a model component. A component can be
// a structured subcomponent or a variable, parameter or constant. All of these
Expand All @@ -5627,6 +5638,7 @@ algorithm
equation
//print(" instElement: A component: " +& n +& "\n");
//Debug.fprintln("debug"," instElement " +& n +& " in s:" +& Env.printEnvPathStr(env) +& " m: " +& SCode.printModStr(m) +& " cm : " +& Mod.printModStr(cmod));
//false = stringEqual(n, Absyn.pathLastIdent(t));
m = traverseModAddFinal(m, finalPrefix);
comp = SCode.COMPONENT(n,io,finalPrefix,repl,prot,attr,ts,m,comment,cond,aInfo,cc);
// Fails if multiple decls not identical
Expand Down Expand Up @@ -5870,6 +5882,7 @@ algorithm
attributes=SCode.ATTR(variability=vt),typeSpec = Absyn.TPATH(t,_),cc=cc),_),_,_,_)
local Absyn.ComponentRef tref; SCode.Variability vt;
equation
//false = stringEqual(n, Absyn.pathLastIdent(t));
failure((_,cl,cenv) = Lookup.lookupClass(cache,env, t, false));
s = Absyn.pathString(t);
scope_str = Env.printEnvPathStr(env);
Expand Down

0 comments on commit d73eb81

Please sign in to comment.