Skip to content

Implement "Constructor Promotion" #5291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Preserve doc comment on promoted property
  • Loading branch information
nikic committed Jun 5, 2020
commit abc2cdfdcb59017ed7e74ec444878658415c0ac0
4 changes: 3 additions & 1 deletion Zend/zend_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ enum _zend_ast_kind {
/* 4 child nodes */
ZEND_AST_FOR = 4 << ZEND_AST_NUM_CHILDREN_SHIFT,
ZEND_AST_FOREACH,
ZEND_AST_PARAM,

/* 5 child nodes */
ZEND_AST_PARAM = 5 << ZEND_AST_NUM_CHILDREN_SHIFT,
};

typedef uint16_t zend_ast_kind;
Expand Down
5 changes: 4 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5787,6 +5787,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
zend_ast *var_ast = param_ast->child[1];
zend_ast *default_ast = param_ast->child[2];
zend_ast *attributes_ast = param_ast->child[3];
zend_ast *doc_comment_ast = param_ast->child[4];
zend_string *name = zval_make_interned_string(zend_ast_get_zval(var_ast));
zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
Expand Down Expand Up @@ -5938,8 +5939,10 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall
type = zend_compile_typename(type_ast, /* force_allow_null */ 0, /* use_arena */ 1);
}

zend_string *doc_comment =
doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
zend_declare_typed_property(
scope, name, &default_value, visibility, /* doc_comment */ NULL, type);
scope, name, &default_value, visibility, doc_comment, type);
}
}

Expand Down
10 changes: 6 additions & 4 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,13 @@ optional_visibility_modifier:

parameter:
optional_visibility_modifier optional_type_without_static
is_reference is_variadic T_VARIABLE
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, NULL); }
is_reference is_variadic T_VARIABLE backup_doc_comment
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, NULL,
NULL, $6 ? zend_ast_create_zval_from_str($6) : NULL); }
| optional_visibility_modifier optional_type_without_static
is_reference is_variadic T_VARIABLE '=' expr
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, $7); }
is_reference is_variadic T_VARIABLE backup_doc_comment '=' expr
{ $$ = zend_ast_create_ex(ZEND_AST_PARAM, $1 | $3 | $4, $2, $5, $8,
NULL, $6 ? zend_ast_create_zval_from_str($6) : NULL); }
;


Expand Down
2 changes: 1 addition & 1 deletion ext/reflection/tests/constructor_promotion.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ Class [ <user> class Test ] {
}
}

bool(false)
string(24) "/** @SomeAnnotation() */"