Opened 11 years ago
Closed 3 years ago
#2732 closed defect (fixed)
Default arguments in functions can be incorrectly scoped
Reported by: | Per Östlund | Owned by: | somebody |
---|---|---|---|
Priority: | normal | Milestone: | 1.19.0 |
Component: | New Instantiation | Version: | trunk |
Keywords: | Cc: |
Description
Default arguments in functions are sometimes evaluated in the wrong scope, e.g.:
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
.
Change History (1)
comment:1 by , 3 years ago
Component: | Frontend → New Instantiation |
---|---|
Milestone: | Future → 1.19.0 |
Resolution: | → fixed |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
The first model already worked in the new frontend, the second is fixed in 517b9a7b.