Skip to content

Commit

Permalink
Set UNION bit for internal class union return type
Browse files Browse the repository at this point in the history
Fixes assertion failure reported in:
#7115 (comment)
  • Loading branch information
nikic committed Jul 19, 2021
1 parent a4db743 commit 084d49a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

This comment has been minimized.

Copy link
@TysonAndre

TysonAndre Jul 19, 2021

Contributor

I don't think anything is using intersection types in tentative return types right now and they'd be comparitively rare, but how would those get handled?

EDIT: oh, the call to strchr

This comment has been minimized.

Copy link
@nikic

nikic Jul 19, 2021

Author Member

This code currently doesn't support intersection types (see the parsing above, it only looks for |). We don't have any internal uses of intersection types, so we didn't bother threading through support yet.


const char *start = class_name;
uint32_t j = 0;
Expand Down
43 changes: 25 additions & 18 deletions ext/reflection/tests/ReflectionMethod_tentative_return_type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,24 @@ class MyDateTimeZone extends DateTimeZone
}
}

$methodInfo = new ReflectionMethod(DateTimeZone::class, 'listIdentifiers');

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');
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((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 [ <internal:date> static public method listIdentifiers ] {

Expand All @@ -49,7 +44,7 @@ string(%d) "Method [ <internal:date> static public method listIdentifiers ] {
bool(true)
bool(false)
string(6) "string"
NULL
string(0) ""
string(%d) "Method [ <user, overwrites DateTimeZone, prototype DateTimeZone> static public method listIdentifiers ] {
@@ %s

Expand All @@ -60,3 +55,15 @@ string(%d) "Method [ <user, overwrites DateTimeZone, prototype DateTimeZone> sta
- Return [ string ]
}
"

bool(false)
bool(true)
string(0) ""
string(37) "SplFileInfo|FilesystemIterator|string"
string(191) "Method [ <internal:SPL, overwrites DirectoryIterator, prototype Iterator> public method current ] {

- Parameters [0] {
}
- Tentative return [ SplFileInfo|FilesystemIterator|string ]
}
"

0 comments on commit 084d49a

Please sign in to comment.