Skip to content

Fix duplicate backed enum values at compile time (#9677) - #9916

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-9677-enum-duplicate-backing
Jun 19, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-9677-enum-duplicate-backing

Conversation

@PurHur

@PurHur PurHur commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Extend EnumBackedCaseCheck::validate() to reject backed enum declarations whose case initializers are compile-time duplicate int/string scalars.
  • Align compliance guards and unit tests with compile-time fatal (exit 255) instead of lazy first-access Error for literal duplicates.

php-src reference

  • Zend/zend_enum.c — zend_register_enum_case duplicate backing detection

PHP implementation

  • lib/Compiler/EnumBackedCaseCheck.php — compile-time duplicate backing scan

Verification

php bin/vm.php test/repro/enum_duplicate_value_echo.php
# Fatal error: Duplicate value in enum E for cases A and B (exit 255)

vendor/bin/phpunit test/unit/EnumBackedCaseCheckTest.php
# OK (9 tests, 14 assertions)

vendor/bin/phpunit test/compliance/EnumVMTest.php --filter 'enum_duplicate_backing_value|duplicate_enum_backing_value|enum_duplicate_backing_value_compile'
# OK (3 tests, 3 assertions)

vendor/bin/phpunit test/compliance/DuplicateEnumBackingJITTest.php
# OK (1 test, 1 assertion)

Closes #9677

Made with Cursor

Reject literal duplicate int/string backing values in EnumBackedCaseCheck
so scripts like enum E { case A=1; case B=1; } fail before runtime.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 0e0c9a7 into master Jun 19, 2026
@PurHur
PurHur deleted the agent/issue-9677-enum-duplicate-backing branch June 19, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: duplicate backed enum values — first-use Error missing (re-#9193, Zend/zend_enum.c)

1 participant