From 23668f323db0acc38ed3f5db706e0c82d676dedc Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 4 May 2010 21:00:24 +0200 Subject: [PATCH] fix ticket #145: the result of 'True or 5' must not be coerced into an integer --- Cython/Compiler/ExprNodes.py | 8 ++++++++ tests/bugs.txt | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index eb164973..4eeca967 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -5305,6 +5305,14 @@ class BoolBinopNode(ExprNode): self.operand1.analyse_types(env) self.operand2.analyse_types(env) self.type = PyrexTypes.spanning_type(self.operand1.type, self.operand2.type) + if self.type.is_numeric and self.type is not PyrexTypes.c_bint_type: + # special case: if one of the results is a bint and the other + # is another C integer, we must prevent returning a numeric + # type so that we do not loose the ability to coerce to a + # Python bool + if self.operand1.type is PyrexTypes.c_bint_type or \ + self.operand2.type is PyrexTypes.c_bint_type: + self.type = py_object_type self.operand1 = self.operand1.coerce_to(self.type, env) self.operand2 = self.operand2.coerce_to(self.type, env) diff --git a/tests/bugs.txt b/tests/bugs.txt index c75f5e71..8a3837d4 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -9,7 +9,6 @@ missing_baseclass_in_predecl_T262 cfunc_call_tuple_args_T408 cascaded_list_unpacking_T467 compile.cpp_operators -bint_binop_T145 # CPython regression tests that don't current work: pyregr.test_threadsignals -- 2.26.2