mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
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:
parent
090627048c
commit
7fbfcfa851
20
Zend/tests/type_declarations/variance/mixed_return_type.phpt
Normal file
20
Zend/tests/type_declarations/variance/mixed_return_type.phpt
Normal 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===
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user