Skip to content

Commit

Permalink
Make the self reference check in Lookup recursive (#8535)
Browse files Browse the repository at this point in the history
Fixes #8521
  • Loading branch information
perost committed Feb 11, 2022
1 parent 5fd3b21 commit 2638a98
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
23 changes: 21 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -505,7 +505,7 @@ algorithm
algorithm
(node, state) := lookupFirstIdent(name.name, scope);
then
lookupLocalName(name.path, node, state, context, checkAccessViolations, InstNode.refEqual(node, scope));
lookupLocalName(name.path, node, state, context, checkAccessViolations, isSelfReference(node, scope));

// Fully qualified path, start from top scope.
case Absyn.Path.FULLYQUALIFIED()
Expand All @@ -514,6 +514,25 @@ algorithm
end match;
end lookupName;

function isSelfReference
input InstNode node;
input InstNode scope;
output Boolean res;
protected
InstNode parent = scope;
algorithm
while not InstNode.isEmpty(parent) loop
if InstNode.refEqual(node, parent) then
res := true;
return;
end if;

parent := InstNode.instanceParent(parent);
end while;

res := false;
end isSelfReference;

function lookupNames
input Absyn.Path name;
input InstNode scope;
Expand All @@ -538,7 +557,7 @@ algorithm
algorithm
(node, state) := lookupFirstIdent(name.name, scope);
then
lookupLocalNames(name.path, node, {node}, state, context, InstNode.refEqual(node, scope));
lookupLocalNames(name.path, node, {node}, state, context, isSelfReference(node, scope));

// Fully qualified path, start from top scope.
case Absyn.Path.FULLYQUALIFIED()
Expand Down
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -897,6 +897,7 @@ RecursiveConstants1.mo \
RecursiveExtends1.mo \
RecursiveExtends2.mo \
RecursiveExtends3.mo \
RecursiveExtends4.mo \
RecursiveInst1.mo \
RecursiveInst2.mo \
RecursiveInst3.mo \
Expand Down
22 changes: 22 additions & 0 deletions testsuite/flattening/modelica/scodeinst/RecursiveExtends4.mo
@@ -0,0 +1,22 @@
// name: RecursiveExtends4
// keywords:
// status: correct
// cflags: -d=newInst
//
// Checks that the compiler catches recursive extends.
//

model RecursiveExtends4
extends RecursiveExtends4.A.Icon1;

model A
extends RecursiveExtends4.A.Icon1;

partial class Icon1 end Icon1;
end A;
end RecursiveExtends4;

// Result:
// class RecursiveExtends4
// end RecursiveExtends4;
// endResult

0 comments on commit 2638a98

Please sign in to comment.