Commit 0d241078 authored by Xavier Thompson's avatar Xavier Thompson

Detect syntax errors involving 'mutable' at parsing time

parent 99130c77
...@@ -51,6 +51,7 @@ class Ctx(object): ...@@ -51,6 +51,7 @@ class Ctx(object):
namespace = None namespace = None
templates = None templates = None
allow_struct_enum_decorator = False allow_struct_enum_decorator = False
modifiers = []
def __init__(self, **kwds): def __init__(self, **kwds):
self.__dict__.update(kwds) self.__dict__.update(kwds)
...@@ -2861,6 +2862,8 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag): ...@@ -2861,6 +2862,8 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
exc_val, exc_check = p_exception_value_clause(s) exc_val, exc_check = p_exception_value_clause(s)
with_gil = p_with_gil(s) with_gil = p_with_gil(s)
is_const_method = p_cpp_const_method(s, ctx) is_const_method = p_cpp_const_method(s, ctx)
if 'mutable' in ctx.modifiers:
s.error("Functions cannot be 'mutable'")
return Nodes.CFuncDeclaratorNode(pos, return Nodes.CFuncDeclaratorNode(pos,
base = base, args = args, has_varargs = ellipsis, base = base, args = args, has_varargs = ellipsis,
exception_value = exc_val, exception_check = exc_check, exception_value = exc_val, exception_check = exc_check,
...@@ -3365,6 +3368,8 @@ def p_c_func_or_var_declaration(s, pos, ctx): ...@@ -3365,6 +3368,8 @@ def p_c_func_or_var_declaration(s, pos, ctx):
if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd', 'cpp_class') and not ctx.templates: if ctx.level not in ('module', 'c_class', 'module_pxd', 'c_class_pxd', 'cpp_class') and not ctx.templates:
s.error("C function definition not allowed here") s.error("C function definition not allowed here")
doc, suite = p_suite_with_docstring(s, Ctx(level='function')) doc, suite = p_suite_with_docstring(s, Ctx(level='function'))
if 'mutable' in modifiers:
s.error("Functions cannot be 'mutable'")
result = Nodes.CFuncDefNode(pos, result = Nodes.CFuncDefNode(pos,
visibility = ctx.visibility, visibility = ctx.visibility,
base_type = base_type, base_type = base_type,
......
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