@@ -125,24 +125,30 @@ protected
125125 InstNode ctor_node, out_rec;
126126 Component out_comp;
127127 Class ctor_cls;
128+ InstNode ty_node;
128129algorithm
129- (inputs, locals) := collectRecordParams(node);
130- attr := DAE . FUNCTION_ATTRIBUTES_DEFAULT ;
131- collected := Pointer . create(false );
130+ // The node we get is usually a record instance, with applied modifiers and so on.
131+ // So the first thing we do is to create a "pure" instance of the record.
132+ node := Lookup . lookupLocalSimpleName(InstNode . name(node), InstNode . parentScope(node));
133+ node := Inst . instantiate(node);
134+ Inst . instExpressions(node);
132135
133- // Create a new node for the default constructor .
134- ctor_node := InstNode . replaceClass( Class . NOT_INSTANTIATED (), node);
136+ // Collect the record fields .
137+ (inputs, locals) := collectRecordParams( node);
135138
136- // Create the output record element, using the node created above as parent.
137- out_comp := Component . UNTYPED_COMPONENT (node, listArray({}), Binding . UNBOUND (NONE ()),
138- Binding . UNBOUND (NONE ()), NFComponent . OUTPUT_ATTR , NONE (), Absyn . dummyInfo);
139- out_rec := InstNode . fromComponent("$out" + InstNode . name(node), out_comp, ctor_node);
139+ // Create the output record element, using the instance created above as both parent and type.
140+ out_comp := Component . TYPED_COMPONENT (node, Type . COMPLEX (node, ComplexType . RECORD (node)),
141+ Binding . UNBOUND (NONE ()), Binding . UNBOUND (NONE ()),
142+ NFComponent . OUTPUT_ATTR , NONE (), Absyn . dummyInfo);
143+ out_rec := InstNode . fromComponent("$out" + InstNode . name(node), out_comp, node);
140144
141- // Make a record constructor class and update the node with it .
145+ // Make a record constructor class and create a node for the constructor .
142146 ctor_cls := Class . makeRecordConstructor(inputs, locals, out_rec);
143- ctor_node := InstNode . updateClass (ctor_cls, ctor_node );
147+ ctor_node := InstNode . replaceClass (ctor_cls, node );
144148
145- // Add the constructor to the function cache.
149+ // Create the constructor function and add it to the function cache.
150+ attr := DAE . FUNCTION_ATTRIBUTES_DEFAULT ;
151+ collected := Pointer . create(false );
146152 InstNode . cacheAddFunc(node, Function . FUNCTION (path, ctor_node, inputs,
147153 {out_rec}, locals, {}, Type . UNKNOWN (), attr, collected, Pointer . create(0 )), false );
148154end instDefaultConstructor;
@@ -177,7 +183,7 @@ algorithm
177183 Component . isConst(comp) and Component . hasBinding(comp) then
178184 locals := n :: locals;
179185 else
180- n := InstNode . replaceComponent (Component . makeInput(comp), n);
186+ n := InstNode . updateComponent (Component . makeInput(comp), n);
181187 inputs := n :: inputs;
182188 end if ;
183189 end for ;
0 commit comments