Commit 38977a4f authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Merge pull request #2935 from cython/gh2934_better_excval_errors

GH-2934: improve error reporting for non-constant exception value expressions
parents d5da2dbc 903db90b
...@@ -734,8 +734,8 @@ class CFuncDeclaratorNode(CDeclaratorNode): ...@@ -734,8 +734,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
self.exception_value = ConstNode( self.exception_value = ConstNode(
self.pos, value=return_type.exception_value, type=return_type) self.pos, value=return_type.exception_value, type=return_type)
if self.exception_value: if self.exception_value:
self.exception_value = self.exception_value.analyse_const_expression(env)
if self.exception_check == '+': if self.exception_check == '+':
self.exception_value = self.exception_value.analyse_const_expression(env)
exc_val_type = self.exception_value.type exc_val_type = self.exception_value.type
if (not exc_val_type.is_error if (not exc_val_type.is_error
and not exc_val_type.is_pyobject and not exc_val_type.is_pyobject
...@@ -748,13 +748,11 @@ class CFuncDeclaratorNode(CDeclaratorNode): ...@@ -748,13 +748,11 @@ class CFuncDeclaratorNode(CDeclaratorNode):
"Exception value must be a Python exception or cdef function with no arguments or *.") "Exception value must be a Python exception or cdef function with no arguments or *.")
exc_val = self.exception_value exc_val = self.exception_value
else: else:
self.exception_value = self.exception_value.coerce_to( self.exception_value = self.exception_value.analyse_types(env).coerce_to(
return_type, env).analyse_const_expression(env) return_type, env).analyse_const_expression(env)
exc_val = self.exception_value.get_constant_c_result_code() exc_val = self.exception_value.get_constant_c_result_code()
if exc_val is None: if exc_val is None:
raise InternalError( error(self.exception_value.pos, "Exception value must be constant")
"get_constant_c_result_code not implemented for %s" %
self.exception_value.__class__.__name__)
if not return_type.assignable_from(self.exception_value.type): if not return_type.assignable_from(self.exception_value.type):
error(self.exception_value.pos, error(self.exception_value.pos,
"Exception value incompatible with function return type") "Exception value incompatible with function return type")
......
# mode: error
import math
cdef double cfunc(double x) except math.nan:
return x
_ERRORS = """
5:39: Exception value must be constant
5:39: Not allowed in a constant expression
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment