Opened 6 years ago

Closed 5 years ago

#5225 closed defect (fixed)

Nested record assignments causes invalid code to be generated

Reported by: Per Östlund Owned by: Mahder Alemseged Gebremedhin
Priority: high Milestone: 1.16.0
Component: Code Generation Version: v1.13.0-dev-nightly
Keywords: Cc:

Description

Consider a model that contains nested record instance that's assigned in an algorithm section:

record R
  Real x;
end R;

record R2
  Real y;
  R r;
end R2;

function f
  output R2 res = R2(1.0, R(2.0));
end f;

model M
  R2 r2;
algorithm
  r2 := f();
end M;

The assignment is compiled into a function M_eqFunction_2, where r2 at the end of the function is assigned as:

  data->localData[0]->realVars[1] /* r2.y variable */ = tmp2._y;
  $Pr2$Pr = tmp2._r;

The first assignment is correct, but the second fails to take into account that tmp2._r is itself a record and tried to assign it to the non-existent variable $Pr2$Pr.

This pattern is used in the HelmholtzMedia library, for example in HelmholtzMedia.Examples.Parameter.setSat_parameter (which only works with -d=newInst, but this issue occurs also with the old frontend).

Change History (4)

comment:1 by Matthis Thorade <matthis.thorade@…>, 6 years ago

Subscribing.
I believe the corresponding issue for the old frontend was issue #3089

comment:2 by matthis.thorade@…, 5 years ago

comment:3 by Francesco Casella, 5 years ago

Milestone: Future1.16.0
Owner: changed from Lennart Ochel to Mahder Alemseged Gebremedhin
Status: newassigned

comment:4 by Francesco Casella, 5 years ago

Resolution: fixed
Status: assignedclosed

I guess we can close this ticket.

Regarding the initialization issues, you may want to wait until #5770 is fixed.

Note: See TracTickets for help on using tickets.