Skip to content

Bootstrap: backed enum explicit value — EnumBackedCaseCheck false positive when php-cfg overlay missing (#5397) #5491

Description

@PurHur

Category

bootstrap | language

Problem

Any backed enum whose cases declare an explicit scalar (enum E: int { case A = 1; }) fails at compile time with CompileFatal: Enum case E::A must have a value, even though Zend accepts the source. This blocks essentially all backed-enum language and stdlib work (serialization, gettype(), BackedEnum::from(), etc.) on bin/vm.php.

Root cause: EnumBackedCaseCheck (lib/Compiler/EnumBackedCaseCheck.php) relies on php-cfg marking explicit values via enumCaseHasExplicitValue and/or a non-empty valueBlock. When script/apply-patches.sh has not synced the #5397 overlay into vendor/ircmaxell/php-cfg, both signals are absent for case A = 1, so the check misfires.

php-src reference

  • php/php-src Zend/zend_compile.c — zend_compile_enum_case (backed cases require explicit or auto value)
  • Overlay: patches/overlays/php-cfg/enum-parser-methods.php, script/apply-patches.sh (apply_php_cfg_enum_class_const_overlay)

Repro (failure today)

<?php
enum E: int {
    case A = 1;
}
echo E::A->value, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php                    # 1
php bin/vm.php repro.php 2>&1    # CompileFatal: Enum case E::A must have a value
'
Runtime Result
Zend PHP 8.x 1
bin/vm.php CompileFatal before execution

String-backed enum E: string { case A = 'x'; } fails the same way when overlay is missing.

Scope (this repo)

Module Path
Compiler guard lib/Compiler/EnumBackedCaseCheck.php — treat explicit = expr via valueBlock children or require overlay in Docker/CI
Patches script/apply-patches.sh — fail loudly if #5397 overlay not applied; run in docker-exec image build
Tests extend test/unit/EnumBackedCaseCheckTest.php; compliance test/compliance/cases/language/enum_backed_int_value.phpt

Prefer defensive check (inspect valueBlock) so tar-copy Docker without re-patched vendor still compiles backed enums.

Done when

  • Repro prints 1 on VM in php-compiler:22.04-dev without manual patch steps
  • EnumBackedCaseCheckTest::testBackedEnumCaseWithValueCompiles passes in Docker CI
  • Backed enum without value still compile-fails with Zend message (existing #5397 PHPT)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter EnumBackedCaseCheck'

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions