Skip to content

Commit f3dbd18

Browse files
committed
Preserve doc comment on promoted property
1 parent 68d514b commit f3dbd18

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

Zend/zend_ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ enum _zend_ast_kind {
147147

148148
ZEND_AST_TRY,
149149
ZEND_AST_CATCH,
150-
ZEND_AST_PARAM,
151150
ZEND_AST_PROP_ELEM,
152151
ZEND_AST_CONST_ELEM,
153152

154153
/* 4 child nodes */
155154
ZEND_AST_FOR = 4 << ZEND_AST_NUM_CHILDREN_SHIFT,
156155
ZEND_AST_FOREACH,
156+
ZEND_AST_PARAM,
157157
};
158158

159159
typedef uint16_t zend_ast_kind;

Zend/zend_compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5758,6 +5758,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
57585758
zend_ast *type_ast = param_ast->child[0];
57595759
zend_ast *var_ast = param_ast->child[1];
57605760
zend_ast *default_ast = param_ast->child[2];
5761+
zend_ast *doc_comment_ast = param_ast->child[3];
57615762
zend_string *name = zval_make_interned_string(zend_ast_get_zval(var_ast));
57625763
zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
57635764
zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
@@ -5905,8 +5906,10 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
59055906
type = zend_compile_typename(type_ast, /* force_allow_null */ 0, /* use_arena */ 1);
59065907
}
59075908

5909+
zend_string *doc_comment =
5910+
doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
59085911
zend_declare_typed_property(
5909-
scope, name, &default_value, visibility, /* doc_comment */ NULL, type);
5912+
scope, name, &default_value, visibility, doc_comment, type);
59105913
}
59115914
}
59125915

Zend/zend_language_parser.y

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,13 @@ optional_visibility_modifier:
654654

655655
parameter:
656656
optional_visibility_modifier optional_type_without_static
657-
is_reference is_variadic T_VARIABLE
658-
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, NULL); }
657+
is_reference is_variadic T_VARIABLE backup_doc_comment
658+
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, NULL,
659+
$6 ? zend_ast_create_zval_from_str($6) : NULL); }
659660
| optional_visibility_modifier optional_type_without_static
660-
is_reference is_variadic T_VARIABLE '=' expr
661-
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, $7); }
661+
is_reference is_variadic T_VARIABLE backup_doc_comment '=' expr
662+
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, $8,
663+
$6 ? zend_ast_create_zval_from_str($6) : NULL); }
662664
;
663665

664666

ext/reflection/tests/constructor_promotion.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ Class [ <user> class Test ] {
4848
}
4949
}
5050

51-
bool(false)
51+
string(24) "/** @SomeAnnotation() */"

0 commit comments

Comments
 (0)