Add broken FS switch behaviour for compatibility.

In the absence of a 'default' label within a switch, FS falls through to the first CASE label (or to the code before the first CASE if there's any).

This commit adds an option, active by default for FS compatibility, that mimics this broken behaviour, as well as a warning in case the 'default' label is absent, which also triggers another warning when the option is active.
This commit is contained in:
Sei Lisa 2016-05-06 20:15:46 +02:00
parent bb198b3745
commit b1b84a123e
2 changed files with 18 additions and 5 deletions

View file

@ -1674,10 +1674,15 @@ list lazy_list_set(list L, integer i, list v)
]})
if switchcasedefault is None:
switchcasedefault = brk
self.breakstack[-1][2] = True
prelude.append({'nt':'JUMP', 't':None, 'name':switchcasedefault,
'scope':blkscope})
warning("No 'default:' label in switch statement")
if self.brokennodefault:
warning("Broken behaviour active - falling through")
if not self.brokennodefault:
switchcasedefault = brk
self.breakstack[-1][2] = True
if switchcasedefault is not None:
prelude.append({'nt':'JUMP', 't':None, 'name':switchcasedefault,
'scope':blkscope})
last = self.breakstack.pop()
if last[2]:
blk.append({'nt':'@', 'name':brk, 'scope':blkscope})
@ -2311,6 +2316,9 @@ list lazy_list_set(list L, integer i, list v)
if self.enableswitch:
self.keywords |= frozenset(('switch', 'case', 'break'))
# Broken behaviour in the absence of a default: label in a switch stmt.
self.brokennodefault = 'brokennodefault' in options
# Allow brackets for assignment of list elements e.g. mylist[5]=4
self.lazylists = 'lazylists' in options