From 7fbfcfa8515341ffdafd934fe6a014fd50bdf269 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 10 May 2021 09:45:48 +0200 Subject: [PATCH] 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". --- .../variance/mixed_return_type.phpt | 20 +++++++++++++++++++ Zend/zend_inheritance.c | 7 +++++++ 2 files changed, 27 insertions(+) create mode 100644 Zend/tests/type_declarations/variance/mixed_return_type.phpt diff --git a/Zend/tests/type_declarations/variance/mixed_return_type.phpt b/Zend/tests/type_declarations/variance/mixed_return_type.phpt new file mode 100644 index 00000000000..45b2440b972 --- /dev/null +++ b/Zend/tests/type_declarations/variance/mixed_return_type.phpt @@ -0,0 +1,20 @@ +--TEST-- +Everything is trivially a subtype of mixed +--FILE-- + +===DONE=== +--EXPECT-- +===DONE=== diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index 4b161692af7..b00c5e5c60b 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -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);