Skip to content

Language: generator with never return type and yield — compile-time fatal missing (zend_compile.c) #7351

Closed

Description

@PurHur

Category

language · php-src-strict

Problem

A function that yields cannot declare return type never. Zend rejects this at compile time:

Generator return type must be a supertype of Generator, never given

This compiler accepts the function (php bin/vm.php exits 0), so invalid generator signatures compile and can reach JIT/AOT.

php-src reference

Repro

Committed: test/repro-maintainer/parity_never_generator_yield.php

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -l test/repro-maintainer/parity_never_generator_yield.php
php bin/vm.php test/repro-maintainer/parity_never_generator_yield.php; echo vm_exit=$?'
Runtime Result
Zend PHP Compile fatal: Generator return type must be a supertype of Generator, never given
bin/vm.php Compiles and runs (exit 0) — gap

Scope (PHP-in-PHP first)

Path Work
lib/Compiler.php / generator lowering Reject never return on functions containing yield/yield from with Zend message
Tests test/compliance/cases/language/never_generator_compile.phpt

Done when

  • Repro fails at compile time on VM with Zend message
  • Ordinary never functions without yield still compile
  • ./script/ci-fast.sh --filter never_generator_compile green on VM

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 Jun 7, 2026
  2. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-b — starting this run

  3. PurHur commented on Jun 7, 2026

    @PurHur
    OwnerAuthor

    Merged via #7357.

    Fix: GeneratorNeverReturnCompileCheck rejects functions with yield/yield from and return type never at compile time with Zend message: `Generator return type must be a supertype of Generator, never given`.

    Verification:

    • Repro: `php bin/vm.php test/repro-maintainer/parity_never_generator_yield.php` → exit 255, compile fatal
    • Unit: `vendor/bin/phpunit --filter GeneratorNeverReturnCompileTest` → OK (5 tests)
    • Compliance: `vendor/bin/phpunit --filter never_generator_compile` → OK (1 test)
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