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.
This commit is contained in:
Nikita Popov 2021-11-15 11:03:03 +01:00
parent c0441f9377
commit 68ca3879d7
4 changed files with 17 additions and 2 deletions

View File

@ -273,6 +273,9 @@ typedef struct {
#define ZEND_TYPE_INIT_PTR_MASK(ptr, type_mask) \
{ (void *) (ptr), (type_mask) }
#define ZEND_TYPE_INIT_UNION(ptr, extra_flags) \
{ (void *) (ptr), (_ZEND_TYPE_LIST_BIT|_ZEND_TYPE_UNION_BIT) | (extra_flags) }
#define ZEND_TYPE_INIT_CLASS(class_name, allow_null, extra_flags) \
ZEND_TYPE_INIT_PTR(class_name, _ZEND_TYPE_NAME_BIT, allow_null, extra_flags)

View File

@ -1460,7 +1460,7 @@ class PropertyInfo
$typeMaskCode = $this->type->toArginfoType()->toTypeMask();
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_PTR(property_{$propertyName}_type_list, _ZEND_TYPE_LIST_BIT, 0, $typeMaskCode);\n";
$code .= "\tzend_type property_{$propertyName}_type = ZEND_TYPE_INIT_UNION(property_{$propertyName}_type_list, $typeMaskCode);\n";
$typeCode = "property_{$propertyName}_type";
} else {
$escapedClassName = $arginfoType->classTypes[0]->toEscapedName();

View File

@ -0,0 +1,12 @@
--TEST--
Union type on internal property
--EXTENSIONS--
zend_test
--FILE--
<?php
$rp = new ReflectionProperty(_ZendTestClass::class, 'classUnionProp');
$rt = $rp->getType();
echo $rt, "\n";
?>
--EXPECT--
stdClass|Iterator|null

View File

@ -252,7 +252,7 @@ static zend_class_entry *register_class__ZendTestClass(zend_class_entry *class_e
property_classUnionProp_type_list->num_types = 2;
property_classUnionProp_type_list->types[0] = (zend_type) ZEND_TYPE_INIT_CLASS(property_classUnionProp_class_stdClass, 0, 0);
property_classUnionProp_type_list->types[1] = (zend_type) ZEND_TYPE_INIT_CLASS(property_classUnionProp_class_Iterator, 0, 0);
zend_type property_classUnionProp_type = ZEND_TYPE_INIT_PTR(property_classUnionProp_type_list, _ZEND_TYPE_LIST_BIT, 0, MAY_BE_NULL);
zend_type property_classUnionProp_type = ZEND_TYPE_INIT_UNION(property_classUnionProp_type_list, MAY_BE_NULL);
zval property_classUnionProp_default_value;
ZVAL_NULL(&property_classUnionProp_default_value);
zend_string *property_classUnionProp_name = zend_string_init("classUnionProp", sizeof("classUnionProp") - 1, 1);