Minor fix for switch node.
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 16 Jul 2008 04:31:18 +0000 (21:31 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 16 Jul 2008 04:31:18 +0000 (21:31 -0700)
Cython/Compiler/Optimize.py
tests/run/switch.pyx

index 77a26a823f55cd67c7ca49d78bb8fdb50d673e3e..ae4dbcc9239e426406a3495f59faf487427fa7cc 100644 (file)
@@ -71,6 +71,8 @@ class SwitchTransform(Visitor.VisitorTransform):
                 cases.append(Nodes.SwitchCaseNode(pos = if_clause.pos,
                                                   conditions = conditions,
                                                   body = if_clause.body))
+        
+        common_var = unwrap_node(common_var)
         return Nodes.SwitchStatNode(pos = node.pos,
                                     test = common_var,
                                     cases = cases,
index da57451791324797b3fa7e3e15be2cb1747226c5..da5bed14b90387d5ace9af9c046632f278c9cc55 100644 (file)
@@ -25,9 +25,9 @@ __doc__ = u"""
 >>> switch_py(8)
 4
 >>> switch_py(10)
-7
+10
 >>> switch_py(12)
-8
+12
 >>> switch_py(13)
 0
 
@@ -57,9 +57,9 @@ __doc__ = u"""
 >>> switch_c(8)
 4
 >>> switch_c(10)
-7
+10
 >>> switch_c(12)
-8
+12
 >>> switch_c(13)
 0
 """
@@ -86,10 +86,10 @@ def switch_py(x):
         return 3
     elif x in [4,5,7,8]:
         return 4
-    elif x in (10,11): # doesn't work:  (7,8,10,11)
-        return 7
+    elif x in (10,11):
+        return 10
     elif x in (12,):
-        return 8
+        return 12
     else:
         return 0
     return -1
@@ -116,10 +116,10 @@ def switch_c(int x):
         return 3
     elif x in [4,5,7,8]:
         return 4
-    elif x in (10,11): # doesn't work:  (7,8,10,11)
-        return 7
+    elif x in (10,11):
+        return 10
     elif x in (12,):
-        return 8
+        return 12
     else:
         return 0
     return -1