Skip to content

Commit 1a9dfaf

Browse files
committed
Fix doc block assignment for arrow functions
1 parent 6470db7 commit 1a9dfaf

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

Zend/zend_ast.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,37 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_4(zend_ast_kind kind, zend_ast
244244
return ast;
245245
}
246246

247+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_5(zend_ast_kind kind, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4, zend_ast *child5) {
248+
zend_ast *ast;
249+
uint32_t lineno;
250+
251+
ZEND_ASSERT(kind >> ZEND_AST_NUM_CHILDREN_SHIFT == 5);
252+
ast = zend_ast_alloc(zend_ast_size(5));
253+
ast->kind = kind;
254+
ast->attr = 0;
255+
ast->child[0] = child1;
256+
ast->child[1] = child2;
257+
ast->child[2] = child3;
258+
ast->child[3] = child4;
259+
ast->child[4] = child5;
260+
if (child1) {
261+
lineno = zend_ast_get_lineno(child1);
262+
} else if (child2) {
263+
lineno = zend_ast_get_lineno(child2);
264+
} else if (child3) {
265+
lineno = zend_ast_get_lineno(child3);
266+
} else if (child4) {
267+
lineno = zend_ast_get_lineno(child4);
268+
} else if (child5) {
269+
lineno = zend_ast_get_lineno(child5);
270+
} else {
271+
lineno = CG(zend_lineno);
272+
}
273+
ast->lineno = lineno;
274+
275+
return ast;
276+
}
277+
247278
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_list_0(zend_ast_kind kind) {
248279
zend_ast *ast;
249280
zend_ast_list *list;

Zend/zend_ast.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,20 @@ ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_class_const_or_name(zend_ast *
214214

215215
#if ZEND_AST_SPEC
216216
# define ZEND_AST_SPEC_CALL(name, ...) \
217-
ZEND_EXPAND_VA(ZEND_AST_SPEC_CALL_(name, __VA_ARGS__, _4, _3, _2, _1, _0)(__VA_ARGS__))
218-
# define ZEND_AST_SPEC_CALL_(name, _, _4, _3, _2, _1, suffix, ...) \
217+
ZEND_EXPAND_VA(ZEND_AST_SPEC_CALL_(name, __VA_ARGS__, _5, _4, _3, _2, _1, _0)(__VA_ARGS__))
218+
# define ZEND_AST_SPEC_CALL_(name, _, _5, _4, _3, _2, _1, suffix, ...) \
219219
name ## suffix
220220
# define ZEND_AST_SPEC_CALL_EX(name, ...) \
221-
ZEND_EXPAND_VA(ZEND_AST_SPEC_CALL_EX_(name, __VA_ARGS__, _4, _3, _2, _1, _0)(__VA_ARGS__))
222-
# define ZEND_AST_SPEC_CALL_EX_(name, _, _5, _4, _3, _2, _1, suffix, ...) \
221+
ZEND_EXPAND_VA(ZEND_AST_SPEC_CALL_EX_(name, __VA_ARGS__, _5, _4, _3, _2, _1, _0)(__VA_ARGS__))
222+
# define ZEND_AST_SPEC_CALL_EX_(name, _, _6, _5, _4, _3, _2, _1, suffix, ...) \
223223
name ## suffix
224224

225225
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_0(zend_ast_kind kind);
226226
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_1(zend_ast_kind kind, zend_ast *child);
227227
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_2(zend_ast_kind kind, zend_ast *child1, zend_ast *child2);
228228
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_3(zend_ast_kind kind, zend_ast *child1, zend_ast *child2, zend_ast *child3);
229229
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_4(zend_ast_kind kind, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4);
230+
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_5(zend_ast_kind kind, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4, zend_ast *child5);
230231

231232
static zend_always_inline zend_ast * zend_ast_create_ex_0(zend_ast_kind kind, zend_ast_attr attr) {
232233
zend_ast *ast = zend_ast_create_0(kind);
@@ -253,6 +254,11 @@ static zend_always_inline zend_ast * zend_ast_create_ex_4(zend_ast_kind kind, ze
253254
ast->attr = attr;
254255
return ast;
255256
}
257+
static zend_always_inline zend_ast * zend_ast_create_ex_5(zend_ast_kind kind, zend_ast_attr attr, zend_ast *child1, zend_ast *child2, zend_ast *child3, zend_ast *child4, zend_ast *child5) {
258+
zend_ast *ast = zend_ast_create_5(kind, child1, child2, child3, child4, child5);
259+
ast->attr = attr;
260+
return ast;
261+
}
256262

257263
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_list_0(zend_ast_kind kind);
258264
ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_list_1(zend_ast_kind kind, zend_ast *child);

Zend/zend_language_parser.y

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,11 @@ inline_function:
10891089
{ $$ = zend_ast_create_decl(ZEND_AST_CLOSURE, $2 | $13, $1, $3,
10901090
zend_string_init("{closure}", sizeof("{closure}") - 1, 0),
10911091
$5, $7, $11, $8, NULL); CG(extra_fn_flags) = $9; }
1092-
| fn returns_ref '(' parameter_list ')' return_type backup_doc_comment T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags
1093-
{ $$ = zend_ast_create_decl(ZEND_AST_ARROW_FUNC, $2 | $12, $1, $7,
1094-
zend_string_init("{closure}", sizeof("{closure}") - 1, 0), $4, NULL,
1095-
zend_ast_create(ZEND_AST_RETURN, $11), $6, NULL);
1092+
| fn returns_ref backup_doc_comment '(' parameter_list ')' return_type
1093+
T_DOUBLE_ARROW backup_fn_flags backup_lex_pos expr backup_fn_flags
1094+
{ $$ = zend_ast_create_decl(ZEND_AST_ARROW_FUNC, $2 | $12, $1, $3,
1095+
zend_string_init("{closure}", sizeof("{closure}") - 1, 0), $5, NULL,
1096+
zend_ast_create(ZEND_AST_RETURN, $11), $7, NULL);
10961097
((zend_ast_decl *) $$)->lex_pos = $10;
10971098
CG(extra_fn_flags) = $9; }
10981099
;

ext/reflection/tests/bug71767.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,27 @@ $func = function(
2727
) {
2828
};
2929

30+
/** Correct docblock */
31+
$func2 = fn(
32+
/** wrong docblock */
33+
$arg
34+
) => null;
35+
3036
$reflectionFunction = new ReflectionFunction('foo');
3137
$reflectionClass = new ReflectionClass(Foo::class);
3238
$reflectionClosure = new ReflectionFunction($func);
39+
$reflectionArrowFn = new ReflectionFunction($func2);
3340

3441
echo $reflectionFunction->getDocComment() . PHP_EOL;
3542
echo $reflectionClass->getMethod('bar')->getDocComment() . PHP_EOL;
3643
echo $reflectionClosure->getDocComment() . PHP_EOL;
44+
echo $reflectionArrowFn->getDocComment() . PHP_EOL;
3745

3846
echo "Done\n";
3947
?>
4048
--EXPECT--
4149
/** Correct docblock */
4250
/** Correct docblock */
4351
/** Correct docblock */
52+
/** Correct docblock */
4453
Done

0 commit comments

Comments
 (0)