﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3186	Partial binding of record sub-components in functions are lost	Rüdiger Franke	Adrian Pop	"The modifiers on record S, variable s in function precalculation are lost during flattening. See the model below.

Today's test show an increase from 74 to 89 built models for the PowerSystems library, see
    https://test.openmodelica.org/libraries/history/PowerSystems-trend.svg
This is due to the introduction of the workaround M3 of #3183, see
    https://github.com/modelica/PowerSystems/commit/bb0593fd7db98de8af4ead2c2047a280267955ef
Interestingly no compilation error occurs. The simulations fail with divisions by zero, because the record constructor functions are not called.

See the following example:
{{{#!mo
package MissingPrecalculation
  record R
    parameter Integer nr;
    Real[nr] vr;
  end R;

  record S
    parameter Integer ns;
    Real[ns] vs;
  end S;

  function precalculation
    input R r;
    output S s(ns = r.nr);
  algorithm
    s.vs := 2*r.vr;
  end precalculation;

  model M3
    parameter R r(nr = 2, vr = {1, 2});
    record S2 = S(ns = r.nr);
    parameter S2 s = precalculation(r);
  end M3;
end MissingPrecalculation;
}}}

Flattening results in:
{{{#!mo
function MissingPrecalculation.precalculation
  input MissingPrecalculation.R r;
  output MissingPrecalculation.S s;
algorithm
  s.vs := r.vr * 2.0;
end MissingPrecalculation.precalculation;

class MissingPrecalculation.M3
  parameter Integer r.nr = 2;
  parameter Real r.vr[1] = 1.0;
  parameter Real r.vr[2] = 2.0;
  parameter Integer s.ns = s.r.nr;
  parameter Real s.vs[1];
  parameter Real s.vs[2];
end MissingPrecalculation.M3;
}}}

Couldn't the the modifier for ns be kept in the precalculation function and the function call be placed in initial equations:

{{{#!mo
function MissingPrecalculation.precalculation
  input MissingPrecalculation.R r;
  output MissingPrecalculation.S s(ns = r.nr);
algorithm
  s.vs := r.vr * 2.0;
end MissingPrecalculation.precalculation;

class MissingPrecalculation.M3
  parameter Integer r.nr = 2;
  parameter Real r.vr[1] = 1.0;
  parameter Real r.vr[2] = 2.0;
  parameter Integer s.ns(fixed = false);
  parameter Real s.vs[1](fixed = false);
  parameter Real s.vs[2](fixed = false);
initial equation
  s = /*.MissingPrecalculation.S*/(MissingPrecalculation.precalculation(/*.MissingPrecalculation.R*/(r)));
end MissingPrecalculation.M3;
}}}

Any other idea?"	defect	accepted	critical	1.9.2	Frontend	trunk			
