summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-02-23 10:46:26 +0100
committerStefan Behnel <stefan_ml@behnel.de>2019-02-23 10:46:26 +0100
commitff75c96615b91ce2aa6f25c94cc831834bae98f9 (patch)
treee63e8e834ee7ad497150e1adb80969833f4faec1
parent76a51a3f5935405cd29afd546e0e5f5c17448a5e (diff)
downloadcython-ff75c96615b91ce2aa6f25c94cc831834bae98f9.tar.gz
Warn when a numeric exception return value is the same as the default return value.
-rw-r--r--Cython/Compiler/Nodes.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index b51cf394c..e16cc8a1a 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -758,6 +758,15 @@ class CFuncDeclaratorNode(CDeclaratorNode):
if not return_type.assignable_from(self.exception_value.type):
error(self.exception_value.pos,
"Exception value incompatible with function return type")
+ if (return_type.is_int or return_type.is_float) and self.exception_value.has_constant_result():
+ try:
+ type_default_value = float(return_type.default_value)
+ except ValueError:
+ pass
+ else:
+ if self.exception_value.constant_result == type_default_value:
+ warning(self.pos, "Ambiguous exception value, same as default return value: %r" %
+ self.exception_value.constant_result)
exc_check = self.exception_check
if return_type.is_cfunction:
error(self.pos, "Function cannot return a function")