﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
1522	Optimization of default function argument values causes incorrect results when a value is given	Pavol Privitzer	Pavol Privitzer	"For model:
{{{
model bugFun
  function myFun
    input Real[1, :] x = [0,1]; 
    output Real y;
  protected
    Real[1, size(x,2)] locX;
    Integer index;
  algorithm
    index :=1;
    while (index <= size(x,2)) loop
      locX[1,index] := x[1,index];
      index := index + 1;
    end while;
          
    y := locX[1,size(x,2)];

  end myFun;
    
  Real res1;
  Real res2;
equation
  res1 = myFun( {{1,2,3}});
  res2 = myFun( {{1,2,3,4,5}});
end bugFun;
}}}
are expected values
{{{
  res1 = 3 
  res2 = 5
}}}
but both are 2
The problem is an agressive optimization where the
{{{
  y := locX[1,size(x,2)];
}}}
is replaced (in generated code) by
{{{
  y := locX[1,2];
}}}
because of the default value of x[] ...
When one removes the default value of x, everything works fine ..."	defect	closed	high				fixed		Pavol Privitzer Per Östlund
