﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2732	Default arguments in functions can be incorrectly scoped	Per Östlund	somebody	"Default arguments in functions are sometimes evaluated in the wrong scope, e.g.:
{{{#!mo
package P
  function f
    input Real x;
    output Real y;
  algorithm
    y := 2 * x;
  end f;

  constant Real p = 1.0;
  function g = f(x = p);
end P;

model M
  Real p = 2.0;
  Real x = P.g();
end M;
}}}
In this model the default argument {{{p}}} of {{{g.x}}} is evaluated in the scope where the call is done, i.e. M, which results in {{{x = 2.0}}} instead of the expected {{{x = 1.0}}}.

Another example:
{{{
function f
  input Real x;
  input Real r;
  output Real o := x+r;
end f;

model M
  Real x = 2.0;
  function g = f(r=x);
  Real y = g(1.0);
end M;
}}}
In this model the reverse happens, the default argument {{{x}}} of {{{f.x}}} is evaluated by using the value of {{{x}}} in {{{f}}}, not of {{{x}}} in {{{M}}}. So the result becomes {{{y = 2.0}}} instead of the expected {{{y = 3.0}}}."	defect	closed	normal	1.19.0	New Instantiation	trunk	fixed		
