Commit 903db90b authored by Stefan Behnel's avatar Stefan Behnel

GH-2934: improve error reporting for non-constant exception value expressions:...

GH-2934: improve error reporting for non-constant exception value expressions: instead of two errors and a crash, just report it once and explicitly.
parent d5da2dbc
......@@ -734,8 +734,8 @@ class CFuncDeclaratorNode(CDeclaratorNode):
self.exception_value = ConstNode(
self.pos, value=return_type.exception_value, type=return_type)
if self.exception_value:
self.exception_value = self.exception_value.analyse_const_expression(env)
if self.exception_check == '+':
self.exception_value = self.exception_value.analyse_const_expression(env)
exc_val_type = self.exception_value.type
if (not exc_val_type.is_error
and not exc_val_type.is_pyobject
......@@ -748,13 +748,11 @@ class CFuncDeclaratorNode(CDeclaratorNode):
"Exception value must be a Python exception or cdef function with no arguments or *.")
exc_val = self.exception_value
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)
exc_val = self.exception_value.get_constant_c_result_code()
if exc_val is None:
raise InternalError(
"get_constant_c_result_code not implemented for %s" %
self.exception_value.__class__.__name__)
error(self.exception_value.pos, "Exception value must be constant")
if not return_type.assignable_from(self.exception_value.type):
error(self.exception_value.pos,
"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