File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
tests/type_declarations/variance Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Everything is trivially a subtype of mixed
3
+ --FILE--
4
+ <?php
5
+
6
+ spl_autoload_register (function ($ class ) {
7
+ echo "Loading $ class \n" ;
8
+ });
9
+
10
+ class A {
11
+ public function test (): mixed {}
12
+ }
13
+ class B extends A {
14
+ public function test (): X {}
15
+ }
16
+
17
+ ?>
18
+ ===DONE===
19
+ --EXPECT--
20
+ ===DONE===
Original file line number Diff line number Diff line change @@ -436,6 +436,13 @@ static inheritance_status zend_perform_covariant_type_check(
436
436
{
437
437
ZEND_ASSERT (ZEND_TYPE_IS_SET (fe_type ) && ZEND_TYPE_IS_SET (proto_type ));
438
438
439
+ /* Apart from void, everything is trivially covariant to the mixed type.
440
+ * Handle this case separately to ensure it never requires class loading. */
441
+ if (ZEND_TYPE_PURE_MASK (proto_type ) == MAY_BE_ANY &&
442
+ !ZEND_TYPE_CONTAINS_CODE (fe_type , IS_VOID )) {
443
+ return INHERITANCE_SUCCESS ;
444
+ }
445
+
439
446
/* Builtin types may be removed, but not added */
440
447
uint32_t fe_type_mask = ZEND_TYPE_PURE_MASK (fe_type );
441
448
uint32_t proto_type_mask = ZEND_TYPE_PURE_MASK (proto_type );
You can’t perform that action at this time.
0 commit comments