File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,9 @@ def Case(self, *patterns):
308
308
src_loc = tracer .get_src_loc (src_loc_at = 1 )
309
309
switch_data = self ._get_ctrl ("Switch" )
310
310
new_patterns = ()
311
+ if () in switch_data ["cases" ]:
312
+ warnings .warn ("A case defined after the default case will never be active" ,
313
+ SyntaxWarning , stacklevel = 3 )
311
314
# This code should accept exactly the same patterns as `v.matches(...)`.
312
315
for pattern in patterns :
313
316
if isinstance (pattern , str ) and any (bit not in "01- \t " for bit in pattern ):
@@ -357,6 +360,9 @@ def Default(self):
357
360
self ._check_context ("Default" , context = "Switch" )
358
361
src_loc = tracer .get_src_loc (src_loc_at = 1 )
359
362
switch_data = self ._get_ctrl ("Switch" )
363
+ if () in switch_data ["cases" ]:
364
+ warnings .warn ("A case defined after the default case will never be active" ,
365
+ SyntaxWarning , stacklevel = 3 )
360
366
try :
361
367
_outer_case , self ._statements = self ._statements , []
362
368
self ._ctrl_context = None
Original file line number Diff line number Diff line change @@ -497,6 +497,26 @@ def test_Case_outside_Switch_wrong(self):
497
497
with m .Case ():
498
498
pass
499
499
500
+ def test_Case_after_Default_wrong (self ):
501
+ m = Module ()
502
+ with m .Switch (self .w1 ):
503
+ with m .Default ():
504
+ pass
505
+ with self .assertWarnsRegex (SyntaxWarning ,
506
+ r"^A case defined after the default case will never be active$" ):
507
+ with m .Case ():
508
+ pass
509
+
510
+ def test_Default_after_Default_wrong (self ):
511
+ m = Module ()
512
+ with m .Switch (self .w1 ):
513
+ with m .Default ():
514
+ pass
515
+ with self .assertWarnsRegex (SyntaxWarning ,
516
+ r"^A case defined after the default case will never be active$" ):
517
+ with m .Default ():
518
+ pass
519
+
500
520
def test_If_inside_Switch_wrong (self ):
501
521
m = Module ()
502
522
with m .Switch (self .s1 ):
You can’t perform that action at this time.
0 commit comments