Skip to content

Commit 4d1f286

Browse files
committed
Use dedicated error for enum case conflict
1 parent cfc148f commit 4d1f286

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Zend/tests/enum/gh21760.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ enum Direction {
1616

1717
?>
1818
--EXPECTF--
19-
Fatal error: Direction and X define the same constant (Up) in the composition of Direction. However, the definition differs and is considered incompatible. Class was composed in %s on line %d
19+
Fatal error: Cannot use trait X, because constant Up conflicts with enum case Direction::Up in %s on line %d

Zend/zend_inheritance.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,18 @@ static void emit_incompatible_trait_constant_error(
27572757
);
27582758
}
27592759

2760+
static void emit_trait_constant_enum_case_conflict_error(
2761+
const zend_class_entry *ce, const zend_class_constant *trait_constant, zend_string *name
2762+
) {
2763+
zend_error_noreturn(E_COMPILE_ERROR,
2764+
"Cannot use trait %s, because constant %s conflicts with enum case %s::%s",
2765+
ZSTR_VAL(trait_constant->ce->name),
2766+
ZSTR_VAL(name),
2767+
ZSTR_VAL(ce->name),
2768+
ZSTR_VAL(name)
2769+
);
2770+
}
2771+
27602772
static bool do_trait_constant_check(
27612773
zend_class_entry *ce, zend_class_constant *trait_constant, zend_string *name, zend_class_entry **traits, size_t current_trait
27622774
) {
@@ -2771,7 +2783,7 @@ static bool do_trait_constant_check(
27712783
zend_class_constant *existing_constant = Z_PTR_P(zv);
27722784

27732785
if (UNEXPECTED(ZEND_CLASS_CONST_FLAGS(existing_constant) & ZEND_CLASS_CONST_IS_CASE)) {
2774-
emit_incompatible_trait_constant_error(ce, existing_constant, trait_constant, name, traits, current_trait);
2786+
emit_trait_constant_enum_case_conflict_error(ce, trait_constant, name);
27752787
return false;
27762788
}
27772789

0 commit comments

Comments
 (0)