com php-src: Added support for nullavle types in AST pretty printer: Zend/tests/type_declarations/types_in_ast.phpt Zend/z end_ast.c
| From: | Bob Weinand | Date: | Wed, 25 May 2016 10:21:25 +0000 |
| Subject: | com php-src: Added support for nullavle types in AST pretty printer: Zend/tests/type_declarations/types_in_ast.phpt Zend/z end_ast.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-95532@lists.php.net to get a copy of this message | ||
Commit: d248c27ff5535ee92e75c889d6b194e1faa7873f
Author: Dmitry Stogov <dmitry@zend.com> Wed, 25 May 2016 13:21:25 +0300
Parents: a53b8ace1b61aab3031da02a4cdef37c96eb5fe5
Branches: typed_ref_properties
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d248c27ff5535ee92e75c889d6b194e1faa7873f
Log:
Added support for nullavle types in AST pretty printer
Changed paths:
A Zend/tests/type_declarations/types_in_ast.phpt
M Zend/zend_ast.c
Diff:
diff --git a/Zend/tests/type_declarations/types_in_ast.phpt
b/Zend/tests/type_declarations/types_in_ast.phpt
new file mode 100644
index 0000000..8958735
--- /dev/null
+++ b/Zend/tests/type_declarations/types_in_ast.phpt
@@ -0,0 +1,23 @@
+--TEST--
+AST pretty-peinter
+--INI--
+zend.assertions=1
+assert.exception=0
+--FILE--
+<?php
+assert(0 && ($a = function (int $a, ?int $b, int $c = null): ?int {
+ $x = new class {
+ public $a;
+ public int $b;
+ public ?int $c;
+ };
+}));
+?>
+--EXPECTF--
+Warning: assert(): assert(0 && ($a = function (int $a, ?int $b, int $c = null): ?int {
+ $x = new class {
+ public $a;
+ public int $b;
+ public ?int $c;
+ };
+})) failed in %stypes_in_ast.php on line 2
diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c
index fb40acd..f80a0c9 100644
--- a/Zend/zend_ast.c
+++ b/Zend/zend_ast.c
@@ -1061,6 +1061,9 @@ tail_call:
zend_ast_export_ex(str, decl->child[1], 0, indent);
if (decl->child[3]) {
smart_str_appends(str, ": ");
+ if (decl->child[3]->attr & ZEND_TYPE_NULLABLE) {
+ smart_str_appendc(str, '?');
+ }
zend_ast_export_ns_name(str, decl->child[3], 0, indent);
}
if (decl->child[2]) {
@@ -1146,6 +1149,9 @@ simple_list:
}
if (type_ast) {
+ if (type_ast->attr & ZEND_TYPE_NULLABLE) {
+ smart_str_appendc(str, '?');
+ }
zend_ast_export_name(
str, type_ast, 0, indent);
smart_str_appendc(str, ' ');
@@ -1610,6 +1616,9 @@ simple_list:
break;
case ZEND_AST_PARAM:
if (ast->child[0]) {
+ if (ast->child[0]->attr & ZEND_TYPE_NULLABLE) {
+ smart_str_appendc(str, '?');
+ }
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
smart_str_appendc(str, ' ');
}