Partially address bug #78647

Produce a sensible error message for the case where inheritance
should fail. There is still a remaining issue that we sometimes
fail inheritance while we should not.
This commit is contained in:
Nikita Popov 2021-11-05 17:05:55 +01:00
parent c19c380323
commit a2fe8d48b1
2 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,24 @@
--TEST--
Bug #78647: Outstanding dependency obligation
--FILE--
<?php
spl_autoload_register(function ($class) {
if ($class == 'A') {
class A {
function m(): B {}
}
} elseif ($class == 'B') {
class B extends A {
function m(): X {}
}
} else {
class C extends B {}
}
});
new B;
?>
--EXPECTF--
Fatal error: Could not check compatibility between B::m(): X and A::m(): B, because class X is not available in %s on line %d

View file

@ -2548,7 +2548,8 @@ static void report_variance_errors(zend_class_entry *ce) {
} else if (obligation->type == OBLIGATION_PROPERTY_COMPATIBILITY) { } else if (obligation->type == OBLIGATION_PROPERTY_COMPATIBILITY) {
emit_incompatible_property_error(obligation->child_prop, obligation->parent_prop); emit_incompatible_property_error(obligation->child_prop, obligation->parent_prop);
} else { } else {
zend_error_noreturn(E_CORE_ERROR, "Bug #78647"); /* Report variance errors of the dependency, which prevent it from being linked. */
report_variance_errors(obligation->dependency_ce);
} }
} ZEND_HASH_FOREACH_END(); } ZEND_HASH_FOREACH_END();