Skip to content

Commit

Permalink
Fix scoping of enumeration conversion operators (#11619)
Browse files Browse the repository at this point in the history
Fixes #11618
  • Loading branch information
perost committed Nov 21, 2023
1 parent 0900643 commit ab2cac7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ uniontype Function
);
// Create a node from the SCode element.
fnNode := InstNode.new(fn_elem, InstNode.parent(enumNode));
fnNode := InstNode.new(fn_elem, InstNode.parentScope(enumNode, ignoreRedeclare=true));
end makeEnumConversionOp;
function getCachedFuncs
Expand Down
4 changes: 4 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFInstNode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ uniontype InstNode
guard ignoreRedeclare
then parentScope(orig_node);

case CLASS_NODE(nodeType = InstNodeType.REDECLARED_CLASS(parent = scope))
guard ignoreRedeclare
then scope;

case CLASS_NODE() then node.parentScope;
case COMPONENT_NODE() then parentScope(Component.classInstance(Pointer.access(node.component)));
case IMPLICIT_SCOPE() then node.parentScope;
Expand Down
20 changes: 20 additions & 0 deletions testsuite/flattening/modelica/scodeinst/EnumConversion3.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// name: EnumConversion3
// keywords:
// status: correct
// cflags: -d=newInst

model A
replaceable type AE = enumeration(:);
parameter AE ae = AE(1);
end A;

model EnumConversion3
type E = enumeration(one, two, three);
A a(redeclare type AE = E);
end EnumConversion3;

// Result:
// class EnumConversion3
// parameter enumeration(one, two, three) a.ae = E.one;
// end EnumConversion3;
// endResult
1 change: 1 addition & 0 deletions testsuite/flattening/modelica/scodeinst/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ enum7.mo \
enum8.mo \
EnumConversion1.mo \
EnumConversion2.mo \
EnumConversion3.mo \
EnumInvalidLiteralName1.mo \
EnumRangeBinding1.mo \
EnumUnspecified1.mo \
Expand Down

0 comments on commit ab2cac7

Please sign in to comment.