'Error when trying to compile a zero-sized record variable in Dymola

I'm creating an array of records dependent on the number of port connections made in a component. The actual component works fine when the number of connections is 1 or more, but does not work when no connections are made. Looking for input on how to resolve or workaround.

Here is the error:

enter image description here

Below is a MWE:

model RecordIssue
  record Record
    Real a=1;
  end Record;

  parameter Integer nPorts=0 annotation (Dialog(connectorSizing=true));

  Modelica.Fluid.Interfaces.FluidPorts_a ports_a[nPorts];

  // declare record array instance for each port connection
  parameter Record[nPorts] recordInstance={Record() for i in 1:nPorts};

  // this next line is an issue only when nPorts = 0 or no connections made
  Real test[:]=recordInstance[:].a;
end RecordIssue;

The expected/desired behavior would be for the variable test to not exist when nPorts=0, which is the normal behavior for something like Real test[:] = {1.0 for i in 1:nPorts};



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source