Skip to content

Commit ccbc121

Browse files
committed
Cleanup
1 parent 0f3ca15 commit ccbc121

File tree

1 file changed

+33
-45
lines changed

1 file changed

+33
-45
lines changed

Zend/zend_inheritance.c

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -489,17 +489,6 @@ static inheritance_status zend_do_perform_implementation_check(
489489
}
490490
/* }}} */
491491

492-
static inheritance_status perform_delayable_implementation_check(
493-
zend_string **unresolved_class, zend_class_entry *ce,
494-
const zend_function *fe, const zend_function *proto, zend_bool always_error) {
495-
inheritance_status status = zend_do_perform_implementation_check(
496-
unresolved_class, fe, proto);
497-
if (status == INHERITANCE_UNRESOLVED) {
498-
add_compatibility_obligation(ce, fe, proto, always_error);
499-
}
500-
return status;
501-
}
502-
503492
static ZEND_COLD void zend_append_type_hint(smart_str *str, const zend_function *fptr, zend_arg_info *arg_info, int return_hint) /* {{{ */
504493
{
505494

@@ -706,12 +695,33 @@ static void ZEND_COLD emit_incompatible_method_error_or_warning(
706695
error_level, error_verb, child, parent, status, unresolved_class);
707696
}
708697

698+
static void perform_delayable_implementation_check(
699+
zend_class_entry *ce, const zend_function *fe,
700+
const zend_function *proto, zend_bool always_error)
701+
{
702+
zend_string *unresolved_class;
703+
inheritance_status status = zend_do_perform_implementation_check(
704+
&unresolved_class, fe, proto);
705+
706+
if (UNEXPECTED(status != INHERITANCE_SUCCESS)) {
707+
if (EXPECTED(status == INHERITANCE_UNRESOLVED)) {
708+
add_compatibility_obligation(ce, fe, proto, always_error);
709+
} else if (status == INHERITANCE_ERROR) {
710+
if (always_error) {
711+
emit_incompatible_method_error(
712+
E_COMPILE_ERROR, "must", fe, proto, status, unresolved_class);
713+
} else {
714+
emit_incompatible_method_error_or_warning(
715+
fe, proto, status, unresolved_class, always_error);
716+
}
717+
}
718+
}
719+
}
720+
709721
static void do_inheritance_check_on_method(zend_function *child, zend_function *parent, zend_class_entry *ce, zval *child_zv) /* {{{ */
710722
{
711723
uint32_t child_flags;
712724
uint32_t parent_flags = parent->common.fn_flags;
713-
inheritance_status status;
714-
zend_string *unresolved_class;
715725

716726
if (UNEXPECTED(parent_flags & ZEND_ACC_FINAL)) {
717727
zend_error_at_noreturn(E_COMPILE_ERROR, NULL, func_lineno(child),
@@ -790,12 +800,8 @@ static void do_inheritance_check_on_method(zend_function *child, zend_function *
790800
ZEND_FN_SCOPE_NAME(child), ZSTR_VAL(child->common.function_name), zend_visibility_string(parent_flags), ZEND_FN_SCOPE_NAME(parent), (parent_flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
791801
}
792802

793-
status = perform_delayable_implementation_check(
794-
&unresolved_class, ce, child, parent, /*always_error*/0);
795-
if (status == INHERITANCE_ERROR) {
796-
emit_incompatible_method_error_or_warning(
797-
child, parent, status, unresolved_class, /*always_error*/0);
798-
}
803+
perform_delayable_implementation_check(
804+
ce, child, parent, /*always_error*/0);
799805
}
800806
} while (0);
801807
}
@@ -1507,8 +1513,6 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
15071513
{
15081514
zend_function *existing_fn = NULL;
15091515
zend_function *new_fn;
1510-
zend_string *unresolved_class;
1511-
inheritance_status status;
15121516

15131517
if ((existing_fn = zend_hash_find_ptr(&ce->function_table, key)) != NULL) {
15141518
/* if it is the same function with the same visibility and has not been assigned a class scope yet, regardless
@@ -1526,21 +1530,13 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
15261530
if ((existing_fn = zend_hash_find_ptr(*overridden, key)) != NULL) {
15271531
if (existing_fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
15281532
/* Make sure the trait method is compatible with previosly declared abstract method */
1529-
status = perform_delayable_implementation_check(
1530-
&unresolved_class, ce, fn, existing_fn, /*always_error*/ 1);
1531-
if (status == INHERITANCE_ERROR) {
1532-
emit_incompatible_method_error(
1533-
E_COMPILE_ERROR, "must", fn, existing_fn, status, unresolved_class);
1534-
}
1533+
perform_delayable_implementation_check(
1534+
ce, fn, existing_fn, /*always_error*/ 1);
15351535
}
15361536
if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
15371537
/* Make sure the abstract declaration is compatible with previous declaration */
1538-
status = perform_delayable_implementation_check(
1539-
&unresolved_class, ce, existing_fn, fn, /*always_error*/ 1);
1540-
if (status == INHERITANCE_ERROR) {
1541-
emit_incompatible_method_error(
1542-
E_COMPILE_ERROR, "must", existing_fn, fn, status, unresolved_class);
1543-
}
1538+
perform_delayable_implementation_check(
1539+
ce, existing_fn, fn, /*always_error*/ 1);
15441540
return;
15451541
}
15461542
}
@@ -1553,20 +1549,12 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
15531549
} else if (existing_fn->common.fn_flags & ZEND_ACC_ABSTRACT &&
15541550
(existing_fn->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0) {
15551551
/* Make sure the trait method is compatible with previosly declared abstract method */
1556-
status = perform_delayable_implementation_check(
1557-
&unresolved_class, ce, fn, existing_fn, /*always_error*/ 1);
1558-
if (status == INHERITANCE_ERROR) {
1559-
emit_incompatible_method_error(
1560-
E_COMPILE_ERROR, "must", fn, existing_fn, status, unresolved_class);
1561-
}
1552+
perform_delayable_implementation_check(
1553+
ce, fn, existing_fn, /*always_error*/ 1);
15621554
} else if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
15631555
/* Make sure the abstract declaration is compatible with previous declaration */
1564-
status = perform_delayable_implementation_check(
1565-
&unresolved_class, ce, existing_fn, fn, /*always_error*/ 1);
1566-
if (status == INHERITANCE_ERROR) {
1567-
emit_incompatible_method_error(
1568-
E_COMPILE_ERROR, "must", existing_fn, fn, status, unresolved_class);
1569-
}
1556+
perform_delayable_implementation_check(
1557+
ce, existing_fn, fn, /*always_error*/ 1);
15701558
return;
15711559
} else if (UNEXPECTED(existing_fn->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
15721560
/* two traits can't define the same non-abstract method */

0 commit comments

Comments
 (0)