Opened 14 years ago

Last modified 13 years ago

#1407 closed defect (fixed)

sample() with variable as argument

Reported by: rfalkeborn Owned by: rfalkeborn
Priority: high Milestone:
Component: Version:
Keywords: Cc: rfalkeborn,

Description

The model

{{{model illegalSampleModel
Real z(start = 1);

algorithm
when sample(0,z) then

z:= z+1;

end when;
end illegalSampleModel;
}}}

is not allowed in Modelica since the specification only allows parameter expressions as input to sample(). However, checking it produces no warning or error message. When checking the model, this should be detected and an appropriate warning or error message produced (delay() with variable as second argument produces a warning message). Also, sample(1,z) should give a similar error/warning message.

If this is fixed and gives an error message (which to me seems more logical?), the warning for delay(x,x) should probably be changed to an error too.

Change History (5)

comment:2 by Adrian Pop, 14 years ago

It was an error before, but I needed to change it in revision 6119 to a warning because is used like that in MSL! From the log message:

- Static.mo
  + Static.elabBuiltinDelay
    delay(x, variable, variable) generates only a warning now as is used inside
    Modelica.Electrical.Analog.Lines.TLine* (where a variable that is an expression of parameters is used)

comment:3 by Martin Sjölund, 14 years ago

Adrian, is this not about sample(), and not delay()?

Anyway, it would be good if we could add an annotation for this.
For example,

__OpenModelica_FunctionInputVariability = {
OpenModelica.Variability.Variable(), // 1st input can be anything
OpenModelica.Variability.Parameter(), // 2nd input has to be param or constant
OpenModelica.Variability.Constant() // 3rd input has to be constant
}

Then we could have fewer builtin handlers and common error messages.

comment:4 by Adrian Pop, 14 years ago

You're right, my mistake!

comment:5 by Martin Sjölund, 13 years ago

In trunk r9623 sample() is now defined as:

function sample
  parameter input Real start(fixed=false);
  parameter input Real interval(fixed=false);
  output Boolean isSample;
  annotation(__OpenModelica_Impure = true);
external "builtin";
end sample;

It checks if the input expressions are parameter expressions. You can also use it for user-defined functions, although that would probably break other compilers :)

Note: See TracTickets for help on using tickets.