Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#3021 closed defect (fixed)

Match switch optimization causes issues with guards

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

Description

Guards on cases in a match rely on the fact that the generated code is a for-switch. When a match is optimized into a switch this no longer works correctly, since the switch won't try another case if the guard is false. Example:

uniontype U
  record INT
    Integer value;
  end INT;

  record REAL
    Real value;
  end REAL;
end U;

function greaterThanZero
  input U u;
  output Boolean b;
algorithm
  b := match(u)
    case INT() guard(u.value > 0) then true;
    case REAL() guard(u.value > 0) then true;
    else false;
  end match;
end greaterThanZero;

function test
algorithm
  greaterThanZero(INT(-2));
end test;

This will simply fail, instead of returning false as expected.

Change History (4)

comment:1 by Martin Sjölund, 10 years ago

I think probably switch with guards should not be allowed to exist ;)
Or we need to add goto on guard fail...

comment:2 by Martin Sjölund, 9 years ago

Milestone: Future1.9.4
Resolution: fixed
Status: newclosed

Fixed in c93aec7

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

Milestone: 1.9.41.9.4-1.9.x

Milestone renamed

comment:4 by Martin Sjölund, 9 years ago

Milestone: 1.9.4-1.9.x1.9.4

Milestone renamed

Note: See TracTickets for help on using tickets.