Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 921ea29

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Redeclare and extends fixes.
- Avoid expanding shared class extends nodes before cloning them. - Added check for short class definition self reference (class A = A). Belonging to [master]: - #2293 - OpenModelica/OpenModelica-testsuite#885
1 parent c2feb3f commit 921ea29

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,14 @@ algorithm
312312
algorithm
313313
// Look up the class that's being derived from and expand it.
314314
ext_node :: _ := Lookup.lookupBaseClassName(Absyn.typeSpecPath(ty), InstNode.parent(node), info);
315+
316+
// Check that the class isn't extending itself, i.e. class A = A.
317+
if referenceEq(ext_node, node) then
318+
Error.addSourceMessage(Error.RECURSIVE_SHORT_CLASS_DEFINITION,
319+
{InstNode.name(node), Dump.unparseTypeSpec(ty)}, info);
320+
fail();
321+
end if;
322+
315323
ext_node := expand(ext_node);
316324

317325
// Fetch the needed information from the class definition and construct a DERIVED_CLASS.
@@ -1106,7 +1114,7 @@ function redeclareClass
11061114
input Modifier outerMod;
11071115
output InstNode redeclaredNode;
11081116
protected
1109-
InstNode orig_node, rdcl_node;
1117+
InstNode orig_node;
11101118
Class orig_cls, rdcl_cls, new_cls;
11111119
Class.Prefixes prefs;
11121120
InstNodeType node_ty;
@@ -1125,7 +1133,7 @@ algorithm
11251133
rdcl_cls := InstNode.getClass(redeclareNode);
11261134

11271135
prefs := mergeRedeclaredClassPrefixes(Class.getPrefixes(orig_cls),
1128-
Class.getPrefixes(rdcl_cls), rdcl_node);
1136+
Class.getPrefixes(rdcl_cls), redeclareNode);
11291137

11301138
if SCode.isClassExtends(InstNode.definition(redeclareNode)) then
11311139
orig_node := expand(originalNode);
@@ -1154,10 +1162,8 @@ algorithm
11541162
rdcl_cls.elements := ClassTree.setClassExtends(orig_node, rdcl_cls.elements);
11551163
rdcl_cls.modifier := Modifier.merge(outerMod, rdcl_cls.modifier);
11561164
rdcl_cls.prefixes := prefs;
1157-
InstNode.updateClass(rdcl_cls, redeclareNode);
1158-
expand(redeclareNode);
11591165
then
1160-
InstNode.getClass(redeclareNode);
1166+
rdcl_cls;
11611167

11621168
// Class extends of a short class declaration.
11631169
case (Class.DERIVED_CLASS(), Class.PARTIAL_CLASS())

0 commit comments

Comments
 (0)