#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 , 10 years ago
comment:2 by , 9 years ago
Milestone: | Future → 1.9.4 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Fixed in c93aec7
Note:
See TracTickets
for help on using tickets.
I think probably switch with guards should not be allowed to exist ;)
Or we need to add goto on guard fail...