Skip to content

Commit 33f49f1

Browse files
committed
Give cdef functions the same position and first line number as def and @cfunc functions, i.e. the one of the outermost (first) decorator, not necessarily the function signature line.
Closes cython#6366
1 parent cd31a17 commit 33f49f1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Cython/Compiler/Parsing.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -2528,6 +2528,7 @@ def p_IF_statement(s: PyrexScanner, ctx):
25282528
@cython.cfunc
25292529
def p_statement(s: PyrexScanner, ctx, first_statement: cython.bint = 0):
25302530
cdef_flag = ctx.cdef_flag
2531+
pos = s.position()
25312532
decorators = None
25322533
if s.sy == 'ctypedef':
25332534
if ctx.level not in ('module', 'module_pxd'):
@@ -2577,7 +2578,7 @@ def p_statement(s: PyrexScanner, ctx, first_statement: cython.bint = 0):
25772578
if ctx.level not in ('module', 'module_pxd', 'function', 'c_class', 'c_class_pxd'):
25782579
s.error('cdef statement not allowed here')
25792580
s.level = ctx.level
2580-
node = p_cdef_statement(s, ctx(overridable=overridable))
2581+
node = p_cdef_statement(s, pos, ctx(overridable=overridable))
25812582
if decorators is not None:
25822583
tup = (Nodes.CFuncDefNode, Nodes.CVarDefNode, Nodes.CClassDefNode)
25832584
if ctx.allow_struct_enum_decorator:
@@ -3461,8 +3462,7 @@ def p_api(s: PyrexScanner) -> cython.bint:
34613462

34623463

34633464
@cython.cfunc
3464-
def p_cdef_statement(s: PyrexScanner, ctx):
3465-
pos = s.position()
3465+
def p_cdef_statement(s: PyrexScanner, pos, ctx):
34663466
ctx.visibility = p_visibility(s, ctx.visibility)
34673467
ctx.api = ctx.api or p_api(s)
34683468
if ctx.api:
@@ -4301,20 +4301,21 @@ def p_cpp_class_definition(s: PyrexScanner, pos, ctx):
43014301

43024302
@cython.cfunc
43034303
def p_cpp_class_attribute(s: PyrexScanner, ctx):
4304+
pos = s.position()
43044305
decorators = None
43054306
if s.sy == '@':
43064307
decorators = p_decorators(s)
43074308
if s.systring == 'cppclass':
4308-
return p_cpp_class_definition(s, s.position(), ctx)
4309+
return p_cpp_class_definition(s, pos, ctx)
43094310
elif s.systring == 'ctypedef':
43104311
return p_ctypedef_statement(s, ctx)
43114312
elif s.sy == 'IDENT' and s.systring in struct_enum_union:
43124313
if s.systring != 'enum':
4313-
return p_cpp_class_definition(s, s.position(), ctx)
4314+
return p_cpp_class_definition(s, pos, ctx)
43144315
else:
4315-
return p_struct_enum(s, s.position(), ctx)
4316+
return p_struct_enum(s, pos, ctx)
43164317
else:
4317-
node = p_c_func_or_var_declaration(s, s.position(), ctx)
4318+
node = p_c_func_or_var_declaration(s, pos, ctx)
43184319
if decorators is not None:
43194320
tup = Nodes.CFuncDefNode, Nodes.CVarDefNode, Nodes.CClassDefNode
43204321
if ctx.allow_struct_enum_decorator:

0 commit comments

Comments
 (0)