fix compiler crash in FlattenInListTransform for non-trivial expressions
authorStefan Behnel <scoder@users.berlios.de>
Wed, 27 Apr 2011 11:35:55 +0000 (13:35 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 27 Apr 2011 11:35:55 +0000 (13:35 +0200)
Cython/Compiler/Optimize.py
tests/run/flatin.pyx

index d4821ca1ee774c885434ad402e3ffe002494bc49..53824cf238c3bb6ebda3d4e147302b6dd7e5b7e1 100644 (file)
@@ -930,7 +930,15 @@ class FlattenInListTransform(Visitor.VisitorTransform, SkipDeclarations):
         conds = []
         temps = []
         for arg in args:
-            if not arg.is_simple():
+            try:
+                # Trial optimisation to avoid redundant temp
+                # assignments.  However, since is_simple() is meant to
+                # be called after type analysis, we ignore any errors
+                # and just play safe in that case.
+                is_simple_arg = arg.is_simple()
+            except Exception:
+                is_simple_arg = False
+            if not is_simple_arg:
                 # must evaluate all non-simple RHS before doing the comparisons
                 arg = UtilNodes.LetRefNode(arg)
                 temps.append(arg)
index 50b9598a3e5be7b1d295b4eff6a31729fe91704a..f210478bd0e00a934199186b2528416be4e9cdc8 100644 (file)
@@ -13,7 +13,7 @@ def test_in(s):
     >>> test_in('')
     5
     """
-    if s in (u'ABC', u'BCD'):
+    if s in (u'ABC', u'BCD', u'ABC'[:3], u'ABC'[::-1], u'ABC'[-1]):
         return 1
     elif s.upper() in (u'ABC', u'BCD'):
         return 2