Skip to content

Language: unit enum (pure enum) declarations — parse + VM (Zend zend_enum.c parity) #3404

Description

@PurHur

Category

language

Problem

Backed enums work (#1356), but pure/unit enums (enum E { case A; }) crash during php-cfg parse. Verified May 2026:

enum E { case A; }
echo E::A->name; // Zend: A

VM today:

PHPCfg\Op\Stmt\Enum_::__construct(): Argument #3 ($implements) must be of type array, PHPCfg\Block given

Backed enum with = values still parses (enum Status: string { case Active = 'x'; }).

php-src reference

Repro (failure today)

<?php
enum E {
    case A;
}
echo E::A->name;
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php; echo vm_exit:$?'
# TypeError in PHPCfg Parser, vm_exit:255

./script/docker-exec.sh -- bash -lc 'php repro.php; echo zend_exit:$?'
# A + zend_exit:0

Scope (this repo)

Module Path
Parser / php-cfg vendor/ircmaxell/php-cfg or patches/*enum* — parseStmt_Enum() unit body
Compiler lib/Compiler.php — TYPE_DECLARE_ENUM / case registration
VM lib/VM.php, lib/VM/BuiltinClasses.php — unit case singletons
Tests test/compliance/cases/language/unit_enum_*.phpt

Done when

Verification

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

Expected behavior (Zend parity)

Implementation hints

  • Fix php-cfg parseStmt_Enum() / patch for unit enum body (case list without scalar type)
  • VM: register unit enum cases as singleton objects with name property
  • Compliance PHPT pair: unit_enum_basic.phpt, unit_enum_case_name.phpt

Related

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on May 29, 2026
  2. PurHur commented on May 29, 2026

    @PurHur
    OwnerAuthor

    claim: runforge-worker-lane-c — starting this run

  3. PurHur commented on May 29, 2026

    @PurHur
    OwnerAuthor

    Verification (runforge-worker-lane-c, this run):

    PR #3411 — unit enum case objects on VM + compile-time JIT lowering.

    • Issue repro: php bin/vm.php -r 'enum E { case A; } echo E::A->name;' → A
    • ./vendor/bin/phpunit --filter unit_enum — 4/4 OK (EnumVMTest + VmUnitEnumTest)
    • ./vendor/bin/phpunit test/compliance/EnumVMTest.php — 5/5 OK (backed + unit)

    php-src ref: Zend/zend_enum.c, Zend/zend_compile.c

    MCJIT execute for enum tests still segfaults on this harness (pre-existing #98); unit_enum PHPTs excluded from JITTest like other VM-first language cases.

  4. PurHur commented on May 30, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — continuing PR #3411 this run

  5. PurHur commented on May 30, 2026

    @PurHur
    OwnerAuthor

    Update (cursor-agent-lane-c): Rebased onto master (#3420 EnumCaseEntry, #3554 clone guard) and rewrote VM path:

    • Unit enum cases stored as singleton TYPE_ENUM_CASE in ClassEntry::constants at TYPE_DECLARE_CLASS_CONST
    • TYPE_PROPERTY_FETCH on ->name / ->value (unit value → undefined property)
    • Variable::equals / === compare enum cases by class + case name

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "enum E { case A; } echo E::A->name;"'
    # A
    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter unit_enum'

    PR #3411 updated on agent/issue-3404-unit-enum. JIT execute remains VM-only (skipped in JITTest).

  6. PurHur commented on May 30, 2026

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-c — continuing open PR #3411 this run

  7. PurHur commented on May 30, 2026

    @PurHur
    OwnerAuthor

    Update (cursor-agent-lane-c): Rebased PR #3411 onto current master (#3420 enum case objects). Remaining #3404 gaps closed:

    • Unit enum cases stored as TYPE_ENUM_CASE singletons at TYPE_DECLARE_CLASS_CONST
    • E::Case === E::Case identity by class + case name
    • ->value on unit enum raises Undefined property: E::$value (Zend message)
    • Compliance: unit_enum_basic.phpt, unit_enum_case_name.phpt, VmUnitEnumTest

    Verification:

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/EnumVMTest.php --filter unit_enum test/unit/VmUnitEnumTest.php'
    # OK (3 tests)

    php-src: Zend/zend_enum.c — unit enum registration, case singletons.

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-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions