@@ -210,19 +210,32 @@ algorithm
210210 if Binding . isBound(binding) then
211211 bindingExp := Binding . getExp(binding);
212212 else
213- bindingExp := buildRecordBinding (node);
213+ bindingExp := buildBinding (node);
214214 end if ;
215215end getBindingExp;
216216
217- function buildRecordBinding
217+ function buildBinding
218218 input InstNode node;
219219 output Expression result;
220220protected
221- InstNode cls_node = InstNode . classScope(node);
222- Class cls = InstNode . getClass(cls_node);
221+ Type ty;
222+ algorithm
223+ ty := InstNode . getType(node);
224+
225+ result := match ty
226+ case Type . ARRAY () guard Type . hasKnownSize(ty) then Expression . fillType(ty, Expression . EMPTY ());
227+ case Type . COMPLEX () then buildRecordBinding(ty. cls);
228+ else Expression . EMPTY ();
229+ end match;
230+ end buildBinding;
231+
232+ function buildRecordBinding
233+ input InstNode recordNode;
234+ output Expression result;
235+ protected
236+ Class cls = InstNode . getClass(recordNode);
223237 array< InstNode > comps;
224238 list< Expression > bindings;
225- Component comp;
226239 Expression exp;
227240algorithm
228241 result := match cls
@@ -231,13 +244,12 @@ algorithm
231244 bindings := {};
232245
233246 for i in arrayLength(comps):-1 :1 loop
234- bindings := getBindingExp(comps[i]) :: bindings;
247+ bindings := Expression . makeMutable( getBindingExp(comps[i]) ) :: bindings;
235248 end for ;
236249 then
237- Expression . RECORD (InstNode . scopePath(cls_node ), cls. ty, bindings);
250+ Expression . RECORD (InstNode . scopePath(recordNode ), cls. ty, bindings);
238251
239252 case Class . TYPED_DERIVED () then buildRecordBinding(cls. baseClass);
240- else Expression . makeMutable(Expression . EMPTY ());
241253 end match;
242254end buildRecordBinding;
243255
@@ -266,12 +278,6 @@ algorithm
266278 local
267279 Option < Expression > repl_exp;
268280
269- case Expression . CREF (cref = ComponentRef . CREF (subscripts = _ :: _))
270- algorithm
271- Error . assertion(false , getInstanceName() + ": missing handling of subscripts" , sourceInfo());
272- then
273- fail();
274-
275281 case Expression . CREF () then applyReplacementCref(repl, exp. cref, exp);
276282 else exp;
277283 end match;
@@ -305,14 +311,18 @@ algorithm
305311 return ;
306312 end if ;
307313
314+ outExp := Expression . applySubscripts(ComponentRef . getSubscripts(listHead(cref_parts)), outExp);
315+ cref_parts := listRest(cref_parts);
316+
308317 if not listEmpty(cref_parts) then
309318 try
310319 // If the cref consists of more than one identifier we need to look up
311320 // the corresponding record field in the expression.
312- for cr in listRest( cref_parts) loop
321+ for cr in cref_parts loop
313322 node := ComponentRef . node(cr);
314323 outExp := Expression . makeImmutable(outExp);
315324 outExp := Expression . lookupRecordField(InstNode . name(node), outExp);
325+ outExp := Expression . applySubscripts(ComponentRef . getSubscripts(cr), outExp);
316326 end for ;
317327 else
318328 Error . assertion(false , getInstanceName() + " could not find replacement for " +
@@ -420,12 +430,13 @@ function assignVariable
420430algorithm
421431 () := match (variable, value)
422432 local
423- Expression val;
433+ Expression var , val;
424434 list< Expression > vals;
435+ Mutable < Expression > var_ptr;
425436
426- case (Expression . MUTABLE (), _)
437+ case (Expression . MUTABLE (exp = var_ptr ), _)
427438 algorithm
428- Mutable . update(variable . exp , assignExp(Mutable . access(variable . exp ), value));
439+ Mutable . update(var_ptr , assignExp(Mutable . access(var_ptr ), value));
429440 then
430441 ();
431442
@@ -438,6 +449,13 @@ algorithm
438449 then
439450 ();
440451
452+ case (Expression . SUBSCRIPTED_EXP (exp = Expression . MUTABLE (exp = var_ptr)), _)
453+ algorithm
454+ Error . assertion(false , getInstanceName() +
455+ ": missing handling of subscripted assignment" , sourceInfo());
456+ then
457+ ();
458+
441459 else
442460 algorithm
443461 Error . assertion(false , getInstanceName() + " failed on " +
0 commit comments