Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5212 closed defect (fixed)

pre(x) in when clause conditions are illegal and should be rejected

Reported by: Francesco Casella Owned by: Per Östlund
Priority: high Milestone: 2.0.0
Component: New Instantiation Version:
Keywords: Cc:

Description

Consider the following test case:

model TestPreReal
  Real x(start = 0, fixed = true);
  Boolean b(start = false, fixed = true);
  
equation
  der(x) = 10;
  when pre(x) > 3 then
    b = true;
  end when;
end TestPreReal;

This code is illegal because the argument of pre() must be a discrete-time expression (Sect. 3.7.3 of the Specification), and expressions containing non-discrete Real variables only become discrete expressions if they are found in the body of a when clause (Sect. 3.8.3 of the Spefication). Hence, not in the condition.

So, this code should be rejected. Instead, it is accepted and generates a simulation code with unspecified behaviour.

Change History (7)

comment:1 by Per Östlund, 6 years ago

Resolution: fixed
Status: newclosed

Fixed in 15fc3f0.

comment:2 by Per Östlund, 6 years ago

I forgot that there are when-statements too. I'll push in a fix for that when Hudson is finished with the first commit.

comment:3 by Per Östlund, 6 years ago

Fixed for when-statements too in 8656356.

comment:4 by Francesco Casella, 6 years ago

I guess this ticket holds the record for the fastest turnaround time :)

in reply to:  4 comment:5 by Per Östlund, 6 years ago

Replying to casella:

I guess this ticket holds the record for the fastest turnaround time :)

I think I've had one or two that where faster. It took some time to add a test case and run the NF tests :)

comment:6 by Per Östlund, 6 years ago

Seems the fix for when-statements caused a test to break though. It looks like there might be some issues with detecting discrete variables.

comment:7 by Per Östlund, 6 years ago

Ok, afd2edb should fix it properly. I didn't propagate the when-flag in all cases when marking variables inside when-clauses as discrete, meaning that e.g. variables inside an if-equation inside a when-equation were ignored.

Note: See TracTickets for help on using tickets.