﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2555	Missing cast for integer array	Leonardo Laguna	Martin Sjölund	"I have the following model that is producing an integer array that is not cast to real array. This case we think should be handled by the frontend.

Check the record 'SomeData' that is initialized with an array of numbers without decimal point.


{{{
model MissingCast
record SomeData
  parameter Real[10] data={1,2,3,4,5,6,7,8,9,10}; /* Integer numbers */
end SomeData;

function getData
  input Real x;
  output Real y;
protected
  SomeData data = SomeData();
  Integer i;
  Boolean finished;
  Real[:] v = data.data;
algorithm
  /* Just some code to avoid evaluate */
  finished:=false;
  i:=1;
  while (not finished) loop
    if x>v[i] then
       finished := true;
    end if;
    i:=i+1;
  end while;
  y:=v[i];
end getData;

Real value;

equation

value = getData(0);

end MissingCast;
}}}

If you flatten the model you will see the following code:


{{{
""function MissingCast.SomeData \""Automatically generated record constructor for MissingCast.SomeData\""
  input Real[10] data = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
  output SomeData res;
end MissingCast.SomeData;

function MissingCast.getData
  input Real x;
  output Real y;
  protected MissingCast.SomeData data = MissingCast.SomeData({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
  protected Integer i;
  protected Boolean finished;
  protected Real[10] v = {data.data[1], data.data[2], data.data[3], data.data[4], data.data[5], data.data[6], data.data[7], data.data[8], data.data[9], data.data[10]};
algorithm
  finished := false;
  i := 1;
  while not finished loop
    if x > v[i] then
      finished := true;
    end if;
    i := 1 + i;
  end while;
  y := v[i];
end MissingCast.getData;

class MissingCast
  Real value;
equation
  value = MissingCast.getData(0.0);
end MissingCast;
""
}}}

The first thing to notice is that the record constructor successfully sets the type of the array.

However  in the body of the function 'MissingCast.getData' there is the following binding:

{{{
protected MissingCast.SomeData data = MissingCast.SomeData({1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
}}}

The array that appears there should be of type real, and if the array is not converted to real, at least should have a cast."	defect	closed	high	1.9.1	Frontend	trunk	fixed		
