Skip to content

Commit 962706d

Browse files
committed
Fix nullable type pretty-printing
1 parent fb09f13 commit 962706d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Zend/tests/assert/expect_015.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ assert(0 && ($a = function () {
2020
yield from $x;
2121
}));
2222

23-
assert(0 && ($a = function &(array &$a, X $b = null) use ($c,&$d) : X {
23+
assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
2424
abstract class A extends B implements C, D {
2525
const X = 12;
2626
const Y = self::X, Z = "aaa";
@@ -161,7 +161,7 @@ Warning: assert(): assert(0 && ($a = function () {
161161
yield from $x;
162162
})) failed in %sexpect_015.php on line %d
163163

164-
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null) use($c, &$d): X {
164+
Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
165165
abstract class A extends B implements C, D {
166166
const X = 12;
167167
const Y = self::X, Z = 'aaa';

Zend/zend_ast.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,9 @@ static void zend_ast_export_ex(smart_str *str, zend_ast *ast, int priority, int
10801080
zend_ast_export_ex(str, decl->child[1], 0, indent);
10811081
if (decl->child[3]) {
10821082
smart_str_appends(str, ": ");
1083+
if (decl->child[3]->attr & ZEND_TYPE_NULLABLE) {
1084+
smart_str_appendc(str, '?');
1085+
}
10831086
zend_ast_export_ns_name(str, decl->child[3], 0, indent);
10841087
}
10851088
if (decl->child[2]) {
@@ -1614,6 +1617,9 @@ static void zend_ast_export_ex(smart_str *str, zend_ast *ast, int priority, int
16141617
break;
16151618
case ZEND_AST_PARAM:
16161619
if (ast->child[0]) {
1620+
if (ast->child[0]->attr & ZEND_TYPE_NULLABLE) {
1621+
smart_str_appendc(str, '?');
1622+
}
16171623
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
16181624
smart_str_appendc(str, ' ');
16191625
}

0 commit comments

Comments
 (0)