Skip to content

Avoid gap in AST_CLASS child nodes for attributes #6088

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 7 additions & 5 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1553,8 +1553,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
break;
case ZEND_AST_CLASS:
decl = (zend_ast_decl *) ast;
if (decl->child[4]) {
zend_ast_export_attributes(str, decl->child[4], indent, 1);
if (decl->child[3]) {
zend_ast_export_attributes(str, decl->child[3], indent, 1);
}
if (decl->flags & ZEND_ACC_INTERFACE) {
smart_str_appends(str, "interface ");
Expand Down Expand Up @@ -1889,8 +1889,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
smart_str_appends(str, "new ");
if (ast->child[0]->kind == ZEND_AST_CLASS) {
zend_ast_decl *decl = (zend_ast_decl *) ast->child[0];
if (decl->child[4]) {
zend_ast_export_attributes(str, decl->child[4], indent, 0);
if (decl->child[3]) {
zend_ast_export_attributes(str, decl->child[3], indent, 0);
}
smart_str_appends(str, "class");
if (zend_ast_get_list(ast->child[1])->children) {
Expand Down Expand Up @@ -2260,10 +2260,12 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
case ZEND_AST_FUNC_DECL:
case ZEND_AST_CLOSURE:
case ZEND_AST_METHOD:
case ZEND_AST_CLASS:
case ZEND_AST_ARROW_FUNC:
((zend_ast_decl *) ast)->child[4] = attr;
break;
case ZEND_AST_CLASS:
((zend_ast_decl *) ast)->child[3] = attr;
break;
case ZEND_AST_PROP_GROUP:
ast->child[2] = attr;
break;
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4501,7 +4501,7 @@ void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */

if (class_ast->kind == ZEND_AST_CLASS) {
/* anon class declaration */
zend_compile_class_decl(&class_node, class_ast, 0);
zend_compile_class_decl(&class_node, class_ast, 0);
} else {
zend_compile_class_ref(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
}
Expand Down Expand Up @@ -7370,8 +7370,8 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /

CG(active_class_entry) = ce;

if (decl->child[4]) {
zend_compile_attributes(&ce->attributes, decl->child[4], 0, ZEND_ATTRIBUTE_TARGET_CLASS);
if (decl->child[3]) {
zend_compile_attributes(&ce->attributes, decl->child[3], 0, ZEND_ATTRIBUTE_TARGET_CLASS);
}

if (implements_ast) {
Expand Down