Re: SWITCH question
- Posted by petelomax Jan 01, 2018
- 2127 views
If I may step in and summarize what has already been said, the thing that is broken is:
Duplicate case entries trigger a compilation error
But http://openeuphoria.org/docs/lang_branch.html#_147_switchstatement does not actually state that, and apparently the compiler does not always implement it correctly (but sometimes it does!).
We are quite used to this
if x=17 then ?"x is 17" elsif x=17 then ?"x is 17 as well" end if
simply (and not really very helpfully) effectively just ignoring the second branch, whereas
switch x do case 17: ?"x is 17" case 17: ?"x is 17 as well" end switch
sometimes crashes, presumably trying to put 17 in the jump table twice. (but use the real examples from #2 above instead)
NB: we do not give a flying monkeys what that should do were it to somehow compile correctly; it should give a compilation error and not run.
One thing that has just struck me is that if the compiler assumes the jump table entry is 0 or some predetermined base offset when calculating jump_table[17]... not that such explains the sporadic behaviour.
Actually, I suspect irv was right and that it is crashing when trying to report the error.
HTH, Pete