From fddf37edf88e8dcee264132a1cbd876e5ea3bc3d Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 27 Apr 2011 13:35:55 +0200 Subject: [PATCH] fix compiler crash in FlattenInListTransform for non-trivial expressions --- Cython/Compiler/Optimize.py | 10 +++++++++- tests/run/flatin.pyx | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) 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 -- 2.26.2