From: Stefan Behnel Date: Wed, 27 Apr 2011 11:35:55 +0000 (+0200) Subject: fix compiler crash in FlattenInListTransform for non-trivial expressions X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=fddf37edf88e8dcee264132a1cbd876e5ea3bc3d;p=cython.git fix compiler crash in FlattenInListTransform for non-trivial expressions --- diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index d4821ca1..53824cf2 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -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) diff --git a/tests/run/flatin.pyx b/tests/run/flatin.pyx index 50b9598a..f210478b 100644 --- a/tests/run/flatin.pyx +++ b/tests/run/flatin.pyx @@ -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