Don't autoload classes during covariant type check against mixed

mixed should be behaving the same way as no type here, and not
require X to be autoloaded. Everything apart from "void" is trivially
covariant to "mixed".
This commit is contained in:
Nikita Popov 2021-05-10 09:45:48 +02:00
parent 090627048c
commit 7fbfcfa851
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,20 @@
--TEST--
Everything is trivially a subtype of mixed
--FILE--
<?php
spl_autoload_register(function($class) {
echo "Loading $class\n";
});
class A {
public function test(): mixed {}
}
class B extends A {
public function test(): X {}
}
?>
===DONE===
--EXPECT--
===DONE===

View File

@ -429,6 +429,13 @@ static inheritance_status zend_perform_covariant_type_check(
{
ZEND_ASSERT(ZEND_TYPE_IS_SET(fe_type) && ZEND_TYPE_IS_SET(proto_type));
/* Apart from void, everything is trivially covariant to the mixed type.
* Handle this case separately to ensure it never requires class loading. */
if (ZEND_TYPE_PURE_MASK(proto_type) == MAY_BE_ANY &&
!ZEND_TYPE_CONTAINS_CODE(fe_type, IS_VOID)) {
return INHERITANCE_SUCCESS;
}
/* Builtin types may be removed, but not added */
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK(fe_type);
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK(proto_type);