From 084d49a262fd9bda6a1c8539ae09a4542a19bd7c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 19 Jul 2021 16:24:19 +0200 Subject: [PATCH] Set UNION bit for internal class union return type Fixes assertion failure reported in: https://github.com/php/php-src/pull/7115#issuecomment-882580767 --- Zend/zend_API.c | 1 + ...eflectionMethod_tentative_return_type.phpt | 43 +++++++++++-------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index cb81ab79628..56cd33986b9 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -2806,6 +2806,7 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend zend_type_list *list = malloc(ZEND_TYPE_LIST_SIZE(num_types)); list->num_types = num_types; ZEND_TYPE_SET_LIST(new_arg_info[i].type, list); + ZEND_TYPE_FULL_MASK(new_arg_info[i].type) |= _ZEND_TYPE_UNION_BIT; const char *start = class_name; uint32_t j = 0; diff --git a/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt b/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt index 576b8717229..d1b5c49c2cb 100644 --- a/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt +++ b/ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt @@ -12,29 +12,24 @@ class MyDateTimeZone extends DateTimeZone } } -$methodInfo = new ReflectionMethod(DateTimeZone::class, 'listIdentifiers'); +function printInfo(ReflectionMethod $methodInfo) { + var_dump($methodInfo->hasReturnType()); + var_dump($methodInfo->hasTentativeReturnType()); + var_dump((string) $methodInfo->getReturnType()); + var_dump((string) $methodInfo->getTentativeReturnType()); + var_dump((string) $methodInfo); + echo "\n"; +} -var_dump($methodInfo->hasReturnType()); -var_dump($methodInfo->hasTentativeReturnType()); -var_dump($methodInfo->getReturnType()); -var_dump((string) $methodInfo->getTentativeReturnType()); -var_dump((string) $methodInfo); -echo "\n"; - -$methodInfo = new ReflectionMethod(MyDateTimeZone::class, 'listIdentifiers'); - -var_dump($methodInfo->hasReturnType()); -var_dump($methodInfo->hasTentativeReturnType()); -var_dump((string) $methodInfo->getReturnType()); -var_dump($methodInfo->getTentativeReturnType()); -var_dump((string) $methodInfo); -echo "\n"; +printInfo(new ReflectionMethod(DateTimeZone::class, 'listIdentifiers')); +printInfo(new ReflectionMethod(MyDateTimeZone::class, 'listIdentifiers')); +printInfo(new ReflectionMethod(FileSystemIterator::class, 'current')); ?> --EXPECTF-- bool(false) bool(true) -NULL +string(0) "" string(5) "array" string(%d) "Method [ static public method listIdentifiers ] { @@ -49,7 +44,7 @@ string(%d) "Method [ static public method listIdentifiers ] { bool(true) bool(false) string(6) "string" -NULL +string(0) "" string(%d) "Method [ static public method listIdentifiers ] { @@ %s @@ -60,3 +55,15 @@ string(%d) "Method [ sta - Return [ string ] } " + +bool(false) +bool(true) +string(0) "" +string(37) "SplFileInfo|FilesystemIterator|string" +string(191) "Method [ public method current ] { + + - Parameters [0] { + } + - Tentative return [ SplFileInfo|FilesystemIterator|string ] +} +"