Skip to content

Commit

Permalink
Warn when a numeric exception return value is the same as the default…
Browse files Browse the repository at this point in the history
… return value.
  • Loading branch information
scoder committed Feb 23, 2019
1 parent 76a51a3 commit ff75c96
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cython/Compiler/Nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,15 @@ def analyse(self, return_type, env, nonempty=0, directive_locals=None, visibilit
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")
Expand Down

0 comments on commit ff75c96

Please sign in to comment.