Opened 11 years ago

Closed 11 years ago

#2729 closed defect (fixed)

Short class definition for functions without parameter

Reported by: Martin Sjölund Owned by: Per Östlund
Priority: high Milestone: 1.9.1
Component: Frontend Version: trunk
Keywords: Cc:

Description

The following works fine if p is a parameter (same pattern used by gravityAcceleration):

function f
  input Real x;
  input Real r;
  output Real o := x+r;
end f;

model M
  Real p = 2.0;
  function g = f(r=p);
  Real x = g(1.0);
end M;

Why? The error-message is horrible.

Change History (2)

comment:1 by Per Östlund, 11 years ago

The issue can be fixed for this particular model by making sure that the evaluation of function parameter default bindings doesn't try to evaluate crefs which are not defined in the function (i.e. p in this case). Doing so is rather trivial since we know what components a function has.

This has two problems though:

  1. The crefs of the modifier of the derived function will be looked up in the scope of the function call.
  2. Function parameters will have precedence over the actually referenced component, since we don't know where a default binding came from. So if f would have a function parameter called p, then it would be used when evaluating r=p instead.

So fixing this issue the easy way will unfortunately mean that functions can silently be incorrectly evaluated, giving the wrong result. And fixing it the hard way is hard...

comment:2 by Per Östlund, 11 years ago

Resolution: fixed
Status: newclosed

Thinking on it a bit more I realized that both of the above points are already an issue even without my fixes, so I've committed them anyway. I'll close this ticket since it's fixed, but will open a new one for the issues I outlined above.

Note: See TracTickets for help on using tickets.