Skip to content

Fix enum cases() static dispatch (#5507) - #5521

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-5507-enum-cases-static
Jun 4, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-5507-enum-cases-static

Conversation

@PurHur

@PurHur PurHur commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Always register synthetic Enum::cases() as public static after enum body lowering (EnumSupport::ensureBuiltinCasesMethod), replacing any stale non-static stub.
  • Fast-path VM initStaticCallable and JIT static-call checks for cases() on enums (parity with from/tryFrom).
  • Add backed-enum spread compliance PHPT and unit smoke.

Closes #5507

php-src reference

Zend/zend_enum.c — zend_enum_list_cases / static cases() on UnitEnum and BackedEnum.

PHP implementation

  • lib/VM/EnumSupport.php — builtin cases() registration
  • lib/VM.php — static dispatch + post-defineClass finalize
  • lib/JIT.php — JIT static-call guard

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/EnumVMTest.php --filter enum_cases'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/unit/VmEnumBasicTest.php --filter testBackedEnumCasesSpread'
OK (3 tests, 3 assertions)   # EnumVMTest --filter enum_cases
OK (1 test, 1 assertion)   # VmEnumBasicTest::testBackedEnumCasesSpread

Made with Cursor

Always install UnitEnum/BackedEnum::cases() as a public static builtin after enum body lowering, and fast-path VM/JIT static calls so spread and E::cases() match Zend.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit f57b2fa into master Jun 4, 2026
@PurHur
PurHur deleted the agent/issue-5507-enum-cases-static branch June 4, 2026 06:36
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.

Language: UnitEnum::cases() static call — regression vs closed #5462 (zend_enum.c)

1 participant