com php-src: change decl groups: Zend/tests/type_declarations /typed_properties_018.phpt Zend/tests/type_decl arations/typed_properties_025.phpt
Zend/tests/typ e_declarations/typed_properties_036.phpt Zend/z end_ast.c Zend/zend_ast.h Zend/zend_compile.c Zend/zend_language_parser.y

From: Date: Mon, 04 Apr 2016 23:42:15 +0000
Subject: com php-src: change decl groups: Zend/tests/type_declarations /typed_properties_018.phpt Zend/tests/type_decl arations/typed_properties_025.phpt
Zend/tests/typ e_declarations/typed_properties_036.phpt Zend/z end_ast.c Zend/zend_ast.h Zend/zend_compile.c Zend/zend_language_parser.y
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95646@lists.php.net to get a copy of this message
Commit: cce2414b4b1ba23a0d73ed38336d15dbe3b1335b Author: Joe Watkins <krakjoe@php.net> Tue, 5 Apr 2016 00:42:15 +0100 Parents: c6eb6d25ad2611b419a17f125a0be7259d248669 Branches: typed_ref_properties Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cce2414b4b1ba23a0d73ed38336d15dbe3b1335b Log: change decl groups Changed paths: M Zend/tests/type_declarations/typed_properties_018.phpt M Zend/tests/type_declarations/typed_properties_025.phpt M Zend/tests/type_declarations/typed_properties_036.phpt M Zend/zend_ast.c M Zend/zend_ast.h M Zend/zend_compile.c M Zend/zend_language_parser.y

diff --git a/Zend/tests/type_declarations/typed_properties_018.phpt b/Zend/tests/type_declarations/typed_properties_018.phpt index f605255..54fd38d 100644 --- a/Zend/tests/type_declarations/typed_properties_018.phpt +++ b/Zend/tests/type_declarations/typed_properties_018.phpt @@ -1,14 +1,20 @@ --TEST-- -Test typed properties disallow mixing typed and untyped declarations +Test typed properties type applies to all props in group --FILE-- <?php class Foo { public int $bar, $qux; } + +$reflector = new ReflectionClass(Foo::class); + +$prop = $reflector->getProperty("qux"); + +var_dump((string) $prop->getType()); ?> --EXPECTF-- -Fatal error: Untyped property Foo::$qux must not be mixed with typed properties in %s on line 3 +string(3) "int" diff --git a/Zend/tests/type_declarations/typed_properties_025.phpt b/Zend/tests/type_declarations/typed_properties_025.phpt index 7979a33..70156de 100644 --- a/Zend/tests/type_declarations/typed_properties_025.phpt +++ b/Zend/tests/type_declarations/typed_properties_025.phpt @@ -1,5 +1,5 @@ --TEST-- -Test typed properties disallow mixing typed and untyped declarations +Test typed properties type must preceed first declaration in group --FILE-- <?php class Foo { @@ -8,7 +8,8 @@ class Foo { } ?> --EXPECTF-- -Fatal error: Typed property Foo::$qux must not be mixed with untyped properties in %s on line 3 +Parse error: syntax error, unexpected 'int' (T_STRING), expecting variable (T_VARIABLE) in %s on line 4 + diff --git a/Zend/tests/type_declarations/typed_properties_036.phpt b/Zend/tests/type_declarations/typed_properties_036.phpt index 5ae25d6..4048e37 100644 --- a/Zend/tests/type_declarations/typed_properties_036.phpt +++ b/Zend/tests/type_declarations/typed_properties_036.phpt @@ -3,8 +3,7 @@ Test typed properties normal foreach must not yield null --FILE-- <?php $foo = new class { - public int $bar = 10, - int $qux; + public int $bar = 10, $qux; }; foreach ($foo as $key => $bar) @@ -13,8 +12,8 @@ foreach ($foo as $key => $bar) string(3) "bar" int(10) -Fatal error: Uncaught TypeError: Typed property class@anonymous::$qux must not be accessed before initialization in %s:7 +Fatal error: Uncaught TypeError: Typed property class@anonymous::$qux must not be accessed before initialization in %s:6 Stack trace: #0 {main} - thrown in %s on line 7 + thrown in %s on line 6 diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 3b93564..cb15699 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1100,7 +1100,12 @@ simple_list: zend_ast_export_var_list(str, (zend_ast_list*)ast, indent); smart_str_appendc(str, ')'); break; - case ZEND_AST_PROP_DECL: + case ZEND_AST_PROP_GROUP: { + zend_ast *type_ast = ast->child[0]; + zend_ast *prop_ast = ast->child[1]; + + ast = prop_ast; + if (ast->attr & ZEND_ACC_PUBLIC) { smart_str_appends(str, "public "); } else if (ast->attr & ZEND_ACC_PROTECTED) { @@ -1111,7 +1116,16 @@ simple_list: if (ast->attr & ZEND_ACC_STATIC) { smart_str_appends(str, "static "); } + + if (type_ast) { + zend_ast_export_name( + str, type_ast, 0, indent); + smart_str_appendc(str, ' '); + } + goto simple_list; + } + case ZEND_AST_CONST_DECL: case ZEND_AST_CLASS_CONST_DECL: smart_str_appends(str, "const "); @@ -1437,14 +1451,9 @@ simple_list: } break; case ZEND_AST_PROP_ELEM: - if (ast->child[0]) { - zend_ast_export_name( - str, ast->child[0], 0, indent); - smart_str_appendc(str, ' '); - } smart_str_appendc(str, '$'); - zend_ast_export_name(str, ast->child[1], 0, indent); - APPEND_DEFAULT_VALUE(2); + zend_ast_export_name(str, ast->child[0], 0, indent); + APPEND_DEFAULT_VALUE(1); case ZEND_AST_CONST_ELEM: zend_ast_export_name(str, ast->child[0], 0, indent); APPEND_DEFAULT_VALUE(1); diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 05a0c29..4943344 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -131,6 +131,7 @@ enum _zend_ast_kind { ZEND_AST_USE_ELEM, ZEND_AST_TRAIT_ALIAS, ZEND_AST_GROUP_USE, + ZEND_AST_PROP_GROUP, /* 3 child nodes */ ZEND_AST_METHOD_CALL = 3 << ZEND_AST_NUM_CHILDREN_SHIFT, @@ -141,11 +142,11 @@ enum _zend_ast_kind { ZEND_AST_CATCH, ZEND_AST_PARAM, ZEND_AST_CONST_ELEM, + ZEND_AST_PROP_ELEM, /* 4 child nodes */ ZEND_AST_FOR = 4 << ZEND_AST_NUM_CHILDREN_SHIFT, - ZEND_AST_FOREACH, - ZEND_AST_PROP_ELEM, + ZEND_AST_FOREACH }; typedef uint16_t zend_ast_kind; diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a000c4a..99ea72a 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5378,13 +5378,12 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */ } /* }}} */ -void zend_compile_prop_decl(zend_ast *ast) /* {{{ */ +void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast) /* {{{ */ { zend_ast_list *list = zend_ast_get_list(ast); uint32_t flags = list->attr; zend_class_entry *ce = CG(active_class_entry); uint32_t i, children = list->children; - zend_bool use_optional_types = 0; if (ce->ce_flags & ZEND_ACC_INTERFACE) { zend_error_noreturn(E_COMPILE_ERROR, "Interfaces may not include member variables"); @@ -5396,10 +5395,9 @@ void zend_compile_prop_decl(zend_ast *ast) /* {{{ */ for (i = 0; i < children; ++i) { zend_ast *prop_ast = list->child[i]; - zend_ast *type_ast = prop_ast->child[0]; - zend_ast *name_ast = prop_ast->child[1]; - zend_ast *value_ast = prop_ast->child[2]; - zend_ast *doc_comment_ast = prop_ast->child[3]; + zend_ast *name_ast = prop_ast->child[0]; + zend_ast *value_ast = prop_ast->child[1]; + zend_ast *doc_comment_ast = prop_ast->child[2]; zend_string *name = zend_ast_get_str(name_ast); zend_string *doc_comment = NULL; zval value_zv; @@ -5412,16 +5410,8 @@ void zend_compile_prop_decl(zend_ast *ast) /* {{{ */ "Typed property %s::$%s must not be static", ZSTR_VAL(ce->name), ZSTR_VAL(name)); - } - - if (!use_optional_types && i > 0) { - zend_error_noreturn(E_COMPILE_ERROR, - "Typed property %s::$%s must not be mixed with untyped properties", - ZSTR_VAL(ce->name), - ZSTR_VAL(name)); - } + } - use_optional_types = 1; if (type_ast->kind == ZEND_AST_TYPE) { optional_type = type_ast->attr; } else { @@ -5458,11 +5448,6 @@ void zend_compile_prop_decl(zend_ast *ast) /* {{{ */ optional_type_name = class_name; } } - } else if (use_optional_types) { - zend_error_noreturn(E_COMPILE_ERROR, - "Untyped property %s::$%s must not be mixed with typed properties", - ZSTR_VAL(ce->name), - ZSTR_VAL(name)); } /* Doc comment has been appended as last element in ZEND_AST_PROP_ELEM ast */ @@ -5519,6 +5504,14 @@ void zend_compile_prop_decl(zend_ast *ast) /* {{{ */ } /* }}} */ +void zend_compile_prop_group(zend_ast *list) /* {{{ */ +{ + zend_ast *type_ast = list->child[0]; + zend_ast *prop_ast = list->child[1]; + + zend_compile_prop_decl(prop_ast, type_ast); +} /* }}} */ + void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */ { zend_ast_list *list = zend_ast_get_list(ast); @@ -7594,8 +7587,8 @@ void zend_compile_stmt(zend_ast *ast) /* {{{ */ case ZEND_AST_METHOD: zend_compile_func_decl(NULL, ast); break; - case ZEND_AST_PROP_DECL: - zend_compile_prop_decl(ast); + case ZEND_AST_PROP_GROUP: + zend_compile_prop_group(ast); break; case ZEND_AST_CLASS_CONST_DECL: zend_compile_class_const_decl(ast); diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index efb0fff..ffa06b9 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -701,8 +701,9 @@ class_statement_list: class_statement: - variable_modifiers property_list ';' - { $$ = $2; $$->attr = $1; } + variable_modifiers optional_type property_list ';' + { $3->attr = $1; + $$ = zend_ast_create(ZEND_AST_PROP_LIST, $2, $3); } | method_modifiers T_CONST class_const_list ';' { $$ = $3; $$->attr = $1; } | T_USE name_list trait_adaptations @@ -800,10 +801,10 @@ property_list: ; property: - optional_type T_VARIABLE backup_doc_comment - { $$ = zend_ast_create(ZEND_AST_PROP_ELEM, $1, $2, NULL, ($3 ? zend_ast_create_zval_from_str($3) : NULL)); } - | optional_type T_VARIABLE '=' expr backup_doc_comment - { $$ = zend_ast_create(ZEND_AST_PROP_ELEM, $1, $2, $4, ($5 ? zend_ast_create_zval_from_str($5) : NULL)); } + T_VARIABLE backup_doc_comment + { $$ = zend_ast_create(ZEND_AST_PROP_ELEM, $1, NULL, ($2 ? zend_ast_create_zval_from_str($2) : NULL)); } + | T_VARIABLE '=' expr backup_doc_comment + { $$ = zend_ast_create(ZEND_AST_PROP_ELEM, $1, $3, ($4 ? zend_ast_create_zval_from_str($4) : NULL)); } ; class_const_list:
« previous php.cvs (#95646) next »