From 343f97968658842faf323fec2fe615642858b48c Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 23 Nov 2010 20:03:45 +0100 Subject: [PATCH] fix constant folding for nonsense code like '-False' --- Cython/Compiler/Optimize.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 62d29e31..c8abd0d4 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -2979,6 +2979,11 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): # this is a safe operation return ExprNodes.FloatNode(node.pos, value = '-' + node.operand.value, constant_result = node.constant_result) + if isinstance(node.operand, ExprNodes.BoolNode): + # not important at all, but simplifies the code below + return ExprNodes.IntNode(node.pos, value = str(node.constant_result), + type = PyrexTypes.c_int_type, + constant_result = node.constant_result) node_type = node.operand.type if node_type.is_int and node_type.signed or \ isinstance(node.operand, ExprNodes.IntNode) and node_type.is_pyobject: -- 2.26.2