Skip to content

Commit 68ca387

Browse files
committed
Fix generation of property with class union type
The generated type was missing the UNION bit. Add a ZEND_TYPE_INIT_UNION macro to hide the implementation details.
1 parent c0441f9 commit 68ca387

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Zend/zend_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ typedef struct {
273273
#define ZEND_TYPE_INIT_PTR_MASK(ptr, type_mask) \
274274
{ (void *) (ptr), (type_mask) }
275275

276+
#define ZEND_TYPE_INIT_UNION(ptr, extra_flags) \
277+
{ (void *) (ptr), (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_UNION_BIT) | (extra_flags) }
278+
276279
#define ZEND_TYPE_INIT_CLASS(class_name, allow_null, extra_flags) \
277280
ZEND_TYPE_INIT_PTR(class_name, _ZEND_TYPE_NAME_BIT, allow_null, extra_flags)
278281

build/gen_stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ public function getDeclaration(): string {
14601460

14611461
$typeMaskCode = $this->type->toArginfoType()->toTypeMask();
14621462

1463-
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_PTR(property_{$propertyName}_type_list, _ZEND_TYPE_LIST_BIT, 0, $typeMaskCode);\n";
1463+
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_UNION(property_{$propertyName}_type_list, $typeMaskCode);\n";
14641464
$typeCode = "property_{$propertyName}_type";
14651465
} else {
14661466
$escapedClassName = $arginfoType->classTypes[0]->toEscapedName();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Union type on internal property
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
$rp = new ReflectionProperty(_ZendTestClass::class, 'classUnionProp');
8+
$rt = $rp->getType();
9+
echo $rt, "\n";
10+
?>
11+
--EXPECT--
12+
stdClass|Iterator|null

ext/zend_test/test_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static zend_class_entry *register_class__ZendTestClass(zend_class_entry *class_e
252252
property_classUnionProp_type_list->num_types = 2;
253253
property_classUnionProp_type_list->types[0] = (zend_type) ZEND_TYPE_INIT_CLASS(property_classUnionProp_class_stdClass, 0, 0);
254254
property_classUnionProp_type_list->types[1] = (zend_type) ZEND_TYPE_INIT_CLASS(property_classUnionProp_class_Iterator, 0, 0);
255-
zend_type property_classUnionProp_type = ZEND_TYPE_INIT_PTR(property_classUnionProp_type_list, _ZEND_TYPE_LIST_BIT, 0, MAY_BE_NULL);
255+
zend_type property_classUnionProp_type = ZEND_TYPE_INIT_UNION(property_classUnionProp_type_list, MAY_BE_NULL);
256256
zval property_classUnionProp_default_value;
257257
ZVAL_NULL(&property_classUnionProp_default_value);
258258
zend_string *property_classUnionProp_name = zend_string_init("classUnionProp", sizeof("classUnionProp") - 1, 1);

0 commit comments

Comments
 (0)