Skip to content

Generator::send() before first resume returns wrong value #338

@nahime0

Description

@nahime0

Description

Calling Generator::send($value) on a fresh generator does not match PHP. PHP starts the generator, injects the sent value into the first suspended yield, and continues execution. The elephc binary instead returns the initial yielded value.

Minimal reproduction

<?php
function gen() {
    $x = yield 10;
    echo "|$x|";
}
$g = gen();
echo $g->send(99);

Steps to reproduce

  1. Save as main.php.
  2. Run php main.php.
  3. Compile and run with elephc.

Expected behavior

PHP 8.4 prints:

|99|

Actual behavior

The elephc-compiled binary prints:

10

Environment

  • elephc 0.23.5
  • PHP 8.4.19
  • macOS arm64
  • reproduced on 2026-06-05

Notes

This suggests the initial send() path is behaving like current()/first yield retrieval instead of the PHP resume semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions