Skip to content

Commit

Permalink
Give error for extends loop.
Browse files Browse the repository at this point in the history
- Give error for a model extending from one of the scopes it's defined
  in.
  • Loading branch information
perost committed Nov 20, 2020
1 parent 34a1da0 commit 0ad86cb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFClassTree.mo
Expand Up @@ -604,6 +604,15 @@ public

case Class.PARTIAL_BUILTIN() then ();

case Class.INSTANCED_CLASS()
guard InstNode.isBaseClass(clsNode)
algorithm
InstNodeType.BASE_CLASS(definition = ext_def) := InstNode.nodeType(clsNode);
Error.addSourceMessage(Error.EXTENDS_LOOP,
{SCodeUtil.getElementName(ext_def)}, InstNode.info(clsNode));
then
fail();

else
algorithm
Error.assertion(false, getInstanceName() + " got invalid class", sourceInfo());
Expand Down
21 changes: 21 additions & 0 deletions testsuite/flattening/modelica/scodeinst/ExtendsLoop1.mo
@@ -0,0 +1,21 @@
// name: ExtendsLoop1
// keywords:
// status: incorrect
// cflags: -d=newInst -i=ExtendsLoop1.M
//

model ExtendsLoop1
model M
extends ExtendsLoop1;
end M;
end ExtendsLoop1;

// Result:
// Error processing file: ExtendsLoop1.mo
// [flattening/modelica/scodeinst/ExtendsLoop1.mo:9:5-9:25:writable] Error: extends ExtendsLoop1 causes an instantiation loop.
//
// # Error encountered! Exiting...
// # Please check the error message and the flags.
//
// Execution failed!
// endResult
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Expand Up @@ -382,6 +382,7 @@ ExtendConnector1.mo \
ExtendImport1.mo \
ExtendImport2.mo \
ExtendInherited1.mo \
ExtendsLoop1.mo \
ExtendReplaceable1.mo \
ExtendReplaceable2.mo \
ExtendReplaceable3.mo \
Expand Down

0 comments on commit 0ad86cb

Please sign in to comment.