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

Commit c06350f

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Fix record constructor generation issue.
Belonging to [master]: - #2446
1 parent c6677a4 commit c06350f

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

Compiler/NFFrontEnd/NFRecord.mo

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,35 @@ protected
129129
algorithm
130130
// The node we get is usually a record instance, with applied modifiers and so on.
131131
// So the first thing we do is to create a "pure" instance of the record.
132-
node := Lookup.lookupLocalSimpleName(InstNode.name(node), InstNode.classScope(InstNode.parent(node)));
133-
node := Inst.instantiate(node);
134-
Inst.instExpressions(node);
132+
133+
// TODO: The lookup will fail for records declared in redeclare modifiers,
134+
// since the parent will be the class scope of the modifier instead of
135+
// the element being modified. In that case we just reinstantiate the
136+
// record completely, but this probably isn't entirely correct. We
137+
// should make the expanded but not fully instantiated class available
138+
// here somehow.
139+
try
140+
ctor_node := Lookup.lookupLocalSimpleName(InstNode.name(node), InstNode.classScope(InstNode.parent(node)));
141+
true := referenceEq(InstNode.definition(node), InstNode.definition(ctor_node));
142+
else
143+
ctor_node := InstNode.replaceClass(Class.NOT_INSTANTIATED(), node);
144+
end try;
145+
146+
ctor_node := Inst.instantiate(ctor_node);
147+
Inst.instExpressions(ctor_node);
135148

136149
// Collect the record fields.
137-
(inputs, locals) := collectRecordParams(node);
150+
(inputs, locals) := collectRecordParams(ctor_node);
138151

139152
// Create the output record element, using the instance created above as both parent and type.
140-
out_comp := Component.UNTYPED_COMPONENT(node, listArray({}),
153+
out_comp := Component.UNTYPED_COMPONENT(ctor_node, listArray({}),
141154
Binding.UNBOUND(NONE()), Binding.UNBOUND(NONE()),
142155
NFComponent.OUTPUT_ATTR, NONE(), Absyn.dummyInfo);
143-
out_rec := InstNode.fromComponent("$out" + InstNode.name(node), out_comp, node);
156+
out_rec := InstNode.fromComponent("$out" + InstNode.name(ctor_node), out_comp, ctor_node);
144157

145158
// Make a record constructor class and create a node for the constructor.
146159
ctor_cls := Class.makeRecordConstructor(inputs, locals, out_rec);
147-
ctor_node := InstNode.replaceClass(ctor_cls, node);
160+
ctor_node := InstNode.replaceClass(ctor_cls, ctor_node);
148161

149162
// Create the constructor function and add it to the function cache.
150163
attr := DAE.FUNCTION_ATTRIBUTES_DEFAULT;

0 commit comments

Comments
 (0)