Opened 14 years ago

Last modified 14 years ago

#1361 closed defect (fixed)

Ranges with negative step (and possibly the ones with start larger than stop) are not handled correctly

Reported by: Adrian Pop Owned by: Adrian Pop
Priority: critical Milestone: White December
Component: Instantiation Version: 1.6.0
Keywords: Cc: Adrian Pop, Adrian Pop, Per Östlund

Description

For example, this model:

model NegativeRange
  parameter Integer start = 10;
  parameter Integer stop = 1;
  parameter Integer step = -1;
  Real a[start-stop + 1] = start:step:stop;
end NegativeRange;

generates:

adrpo@kafka ~/dev/OpenModelicaBackend/build/bin
$ ./omc NegativeRange.mo +d=failtrace +showErrorMessages
class NegativeRange
  parameter Integer start = 10;
  parameter Integer stop = 1;
  parameter Integer step = -1;
  parameter Real a[1];
  parameter Real a[2];
  parameter Real a[3];
  parameter Real a[4];
  parameter Real a[5];
  parameter Real a[6];
  parameter Real a[7];
  parameter Real a[8];
  parameter Real a[9];
  parameter Real a[10];
end NegativeRange;

Change History (2)

comment:1 by Adrian Pop, 14 years ago

Another example:

model NegativeRange
  parameter Integer start = 10;
  parameter Integer step = -1;
  parameter Integer stop = 1;
  parameter Real a[:] = useRange(start, step, stop);

  function useRange
    input Integer start;
    input Integer step;
    input Integer stop;
    output Real r[integer((abs(start-stop)+1)/step)];
  algorithm
    r := start:step:stop;
  end useRange;

end NegativeRange;

with even wronger result as component a disappears:

adrpo@kafka ~/dev/OpenModelicaBackend/build/bin
$ ./omc +s NegativeRange.mo +d=failtrace +showErrorMessages
function NegativeRange.useRange
  input Integer start;
  input Integer step;
  input Integer stop;
  output Real[integer(Real(1 + abs(start - stop)) / Real(step))] r;
algorithm
  r := /*/tp:REAL[:]/*/(start:step:stop);
end NegativeRange.useRange;

class NegativeRange
  parameter Integer start = 10;
  parameter Integer step = -1;
  parameter Integer stop = 1;
end NegativeRange;

Even code generation is wrong as we get:

cast_integer_array_to_real(&UNKNOWN_EXP, &tmp4);

in the generated code.

comment:2 by Per Östlund, 14 years ago

Fixed in r7166.

Note: See TracTickets for help on using tickets.