Skip to content

Commit b815e10

Browse files
committed
Fix handling of ?array and ?callable
Wrap these in AST_NULLABLE_TYPE as well.
1 parent f79568f commit b815e10

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ static void ast_fill_children_ht(HashTable *ht, zend_ast *ast, zend_long version
381381
ast_create_virtual_node_ex(
382382
&child_zv, AST_NULLABLE_TYPE, 0, zend_ast_get_lineno(child), version, 1, &tmp);
383383
}
384+
} else if (child && child->kind == ZEND_AST_TYPE && (child->attr & ZEND_TYPE_NULLABLE)) {
385+
child->attr &= ~ZEND_TYPE_NULLABLE;
386+
ast_create_virtual_node(&child_zv, AST_NULLABLE_TYPE, child, version);
384387
} else if (ast->kind == ZEND_AST_CLOSURE_USES) {
385388
ast_create_virtual_node(&child_zv, AST_CLOSURE_VAR, child, version);
386389
} else if (ast_is_var_name(child, ast, i)) {

tests/nullable_types.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function test(?Foo $foo) : ?Bar {
1313
}
1414
function test(?int $foo) : ?int {
1515
}
16+
function test(?array $foo) : ?array {
17+
}
1618
PHP;
1719

1820
echo ast_dump(ast\parse_code($code, $version=40));
@@ -54,3 +56,19 @@ AST_STMT_LIST
5456
returnType: AST_NULLABLE_TYPE
5557
type: AST_TYPE
5658
flags: TYPE_LONG (4)
59+
2: AST_FUNC_DECL
60+
flags: 0
61+
name: test
62+
params: AST_PARAM_LIST
63+
0: AST_PARAM
64+
flags: 0
65+
type: AST_NULLABLE_TYPE
66+
type: AST_TYPE
67+
flags: TYPE_ARRAY (7)
68+
name: "foo"
69+
default: null
70+
uses: null
71+
stmts: AST_STMT_LIST
72+
returnType: AST_NULLABLE_TYPE
73+
type: AST_TYPE
74+
flags: TYPE_ARRAY (7)

0 commit comments

Comments
 (0)