Skip to content

Commit abc2cdf

Browse files
committed
Preserve doc comment on promoted property
1 parent 72b1bca commit abc2cdf

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

Zend/zend_ast.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ enum _zend_ast_kind {
156156
/* 4 child nodes */
157157
ZEND_AST_FOR = 4 << ZEND_AST_NUM_CHILDREN_SHIFT,
158158
ZEND_AST_FOREACH,
159-
ZEND_AST_PARAM,
159+
160+
/* 5 child nodes */
161+
ZEND_AST_PARAM = 5 << ZEND_AST_NUM_CHILDREN_SHIFT,
160162
};
161163

162164
typedef uint16_t zend_ast_kind;

Zend/zend_compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5787,6 +5787,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
57875787
zend_ast *var_ast = param_ast->child[1];
57885788
zend_ast *default_ast = param_ast->child[2];
57895789
zend_ast *attributes_ast = param_ast->child[3];
5790+
zend_ast *doc_comment_ast = param_ast->child[4];
57905791
zend_string *name = zval_make_interned_string(zend_ast_get_zval(var_ast));
57915792
zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
57925793
zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
@@ -5938,8 +5939,10 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
59385939
type = zend_compile_typename(type_ast, /* force_allow_null */ 0, /* use_arena */ 1);
59395940
}
59405941

5942+
zend_string *doc_comment =
5943+
doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
59415944
zend_declare_typed_property(
5942-
scope, name, &default_value, visibility, /* doc_comment */ NULL, type);
5945+
scope, name, &default_value, visibility, doc_comment, type);
59435946
}
59445947
}
59455948

Zend/zend_language_parser.y

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

694694
parameter:
695695
optional_visibility_modifier optional_type_without_static
696-
is_reference is_variadic T_VARIABLE
697-
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, NULL); }
696+
is_reference is_variadic T_VARIABLE backup_doc_comment
697+
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, NULL,
698+
NULL, $6 ? zend_ast_create_zval_from_str($6) : NULL); }
698699
| optional_visibility_modifier optional_type_without_static
699-
is_reference is_variadic T_VARIABLE '=' expr
700-
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, $7); }
700+
is_reference is_variadic T_VARIABLE backup_doc_comment '=' expr
701+
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, $8,
702+
NULL, $6 ? zend_ast_create_zval_from_str($6) : NULL); }
701703
;
702704

703705

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)