@@ -300,20 +300,24 @@ protected
300300 Visibility vis;
301301 Equation eq;
302302 list< tuple< String , Binding >> ty_attrs;
303+ Variability var ;
304+ Boolean is_fixed;
303305algorithm
304306 Component . TYPED_COMPONENT (ty = ty, binding = binding, attributes = comp_attr,
305307 comment = cmt, info = info) := comp;
308+ var := comp_attr. variability;
306309
307310 if isSome(outerBinding) then
308311 SOME (binding) := outerBinding;
312+ is_fixed := Binding . isUnbound(binding) and var == Variability . PARAMETER ;
309313 else
310314 binding := flattenBinding(binding, prefix);
315+ is_fixed := false ;
311316 end if ;
312317
313318 // If the component is an array component with a binding and at least discrete variability,
314319 // move the binding into an equation. This avoids having to scalarize the binding.
315- if Type . isArray(ty) and Binding . isBound(binding) and
316- Component . variability(comp) >= Variability . DISCRETE then
320+ if Type . isArray(ty) and Binding . isBound(binding) and var >= Variability . DISCRETE then
317321 name := ComponentRef . prefixCref(comp_node, ty, {}, prefix);
318322 eq := Equation . ARRAY_EQUALITY (Expression . CREF (ty, name), Binding . getTypedExp(binding), ty,
319323 ElementSource . createElementSource(info));
@@ -322,8 +326,15 @@ algorithm
322326 end if ;
323327
324328 name := ComponentRef . prefixScope(comp_node, ty, {}, prefix);
325-
326329 ty_attrs := list(flattenTypeAttribute(m, name) for m in typeAttrs);
330+
331+ // Set fixed = true for parameters that are part of a record instance whose
332+ // binding couldn't be split and was moved to an initial equation.
333+ if is_fixed then
334+ ty_attrs := List . removeOnTrue("fixed" , isTypeAttributeNamed, ty_attrs);
335+ ty_attrs := ("fixed" , Binding . FLAT_BINDING (Expression . BOOLEAN (true ), Variability . CONSTANT )) :: ty_attrs;
336+ end if ;
337+
327338 vars := Variable . VARIABLE (name, ty, binding, visibility, comp_attr, ty_attrs, cmt, info) :: vars;
328339end flattenSimpleComponent;
329340
@@ -338,6 +349,17 @@ algorithm
338349 outAttr := (Modifier . name(attr), binding);
339350end flattenTypeAttribute;
340351
352+ function isTypeAttributeNamed
353+ input String name;
354+ input tuple< String , Binding > attr;
355+ output Boolean isNamed;
356+ protected
357+ String attr_name;
358+ algorithm
359+ (attr_name, _) := attr;
360+ isNamed := name == attr_name;
361+ end isTypeAttributeNamed;
362+
341363function getRecordBindings
342364 input Binding binding;
343365 output list< Binding > recordBindings;
@@ -395,7 +417,7 @@ algorithm
395417 binding_exp := Binding . getTypedExp(binding);
396418
397419 comp_var := Component . variability(comp);
398- if comp_var <= Variability . PARAMETER then
420+ if comp_var <= Variability . STRUCTURAL_PARAMETER then
399421 binding_exp := Ceval . evalExp(binding_exp);
400422 else
401423 binding_exp := SimplifyExp . simplify(binding_exp);
@@ -405,7 +427,7 @@ algorithm
405427 name := ComponentRef . prefixCref(node, ty, {}, prefix);
406428 eq := Equation . EQUALITY (Expression . CREF (ty, name), binding_exp, ty,
407429 ElementSource . createElementSource(InstNode . info(node)));
408- sections := Sections . prependEquation(eq, sections);
430+ sections := Sections . prependEquation(eq, sections, isInitial = comp_var <= Variability . PARAMETER );
409431 opt_binding := SOME (NFBinding . EMPTY_BINDING );
410432 else
411433 binding := Binding . setTypedExp(binding_exp, binding);
0 commit comments