diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 778ef394be7a68fa8ecf2c2d8f53b1e6bd962ccc..36b4e560df16a35987881a6e718c863c8db86f31 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -327,8 +327,9 @@ class ExprNode(Node): # time we get the result. self.analyse_types(env) bool = self.coerce_to_boolean(env) - temp_bool = bool.coerce_to_temp(env) - return temp_bool + if not bool.is_simple(): + bool = bool.coerce_to_temp(env) + return bool # --------------- Type Inference ----------------- @@ -6383,6 +6384,7 @@ class CoerceToTempNode(CoercionNode): def __init__(self, arg, env): CoercionNode.__init__(self, arg) self.type = self.arg.type + self.constant_result = self.arg.constant_result self.is_temp = 1 if self.type.is_pyobject: self.result_ctype = py_object_type @@ -6395,6 +6397,8 @@ class CoerceToTempNode(CoercionNode): def coerce_to_boolean(self, env): self.arg = self.arg.coerce_to_boolean(env) + if self.arg.is_simple(): + return self.arg self.type = self.arg.type self.result_ctype = self.type return self diff --git a/tests/errors/break_outside_loop.pyx b/tests/errors/break_outside_loop.pyx index 07ccfeace92af0cf2ca1082e960f86f3de82082f..c28144231657822f1ad0bb6310b3db3558fbe0a2 100644 --- a/tests/errors/break_outside_loop.pyx +++ b/tests/errors/break_outside_loop.pyx @@ -16,11 +16,14 @@ except: pass try: break finally: pass -if True: +if bool_result(): break else: break +def bool_result(): + return True + _ERRORS = u''' 2:0: break statement not inside loop diff --git a/tests/errors/continue_outside_loop.pyx b/tests/errors/continue_outside_loop.pyx index 8c3a38d3cb6bae3f09b7daf0f75e5b9378a50583..f8309158bd64ef67b8b1f320a8f0b87f90cf9d07 100644 --- a/tests/errors/continue_outside_loop.pyx +++ b/tests/errors/continue_outside_loop.pyx @@ -16,11 +16,13 @@ except: pass try: continue finally: pass -if True: +if bool_result(): continue else: continue +def bool_result(): + return True _ERRORS = u''' 2:0: continue statement not inside loop diff --git a/tests/errors/literal_lists.pyx b/tests/errors/literal_lists.pyx index adbff03c71defec92fb6d1aed37cda9360e0a917..7c49f961fc238e8184ecb7244a273f91f90aa808 100644 --- a/tests/errors/literal_lists.pyx +++ b/tests/errors/literal_lists.pyx @@ -1,8 +1,11 @@ def f(): cdef int* p - if False: + if false(): p = [1, 2, 3] +def false(): + return False + _ERRORS = u""" 4:10: Literal list must be assigned to pointer at time of declaration """