conservative fix for empty switch statements
authorStefan Behnel <scoder@users.berlios.de>
Fri, 7 Nov 2008 05:55:37 +0000 (06:55 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 7 Nov 2008 05:55:37 +0000 (06:55 +0100)
Cython/Compiler/Nodes.py
tests/run/switch.pyx

index 119e5d4fe65ebb10ac82421831515f65f1ea5f09..bd583d80b6ded0b320c279422cc1b8537c127acd 100644 (file)
@@ -3469,6 +3469,7 @@ class SwitchStatNode(StatNode):
         if self.else_clause is not None:
             code.putln("default:")
             self.else_clause.generate_execution_code(code)
+            code.putln("break;")
         code.putln("}")
 
     def annotate(self, code):
index 80f16f7d42ecc064adec5afef96ad6ee105c3e69..36ab9287e254bcb29f558a771a7084f0a9febe0c 100644 (file)
@@ -89,6 +89,9 @@ __doc__ = u"""
 1
 >>> switch_off(2)
 0
+
+>>> switch_pass(1)
+1
 """
 
 def switch_simple_py(x):
@@ -173,3 +176,12 @@ def switch_off(int x):
     else:
         return 0
     return -1
+
+def switch_pass(int x):
+    if x == 1:
+        pass
+    elif x == 2:
+        pass
+    else:
+        pass
+    return x