Skip to content

[Bug] yield from return value is lost when captured and yielded by the outer generator #192

@nahime0

Description

@nahime0

Description

When the result of yield from is assigned to a local variable and then used, elephc compiles the program but the generated binary produces no output.

In PHP, yield from evaluates to the delegated generator's return value. That return value should be assigned to the local and remain usable after the delegation completes.

Reproduction

<?php
function inner() {
    yield 1;
    return 42;
}

function outer() {
    $ret = yield from inner();
    yield $ret;
}

foreach (outer() as $v) {
    echo $v;
    echo "\n";
}

PHP output

1
42

elephc behavior

  • The file compiles successfully.
  • The generated binary runs but prints nothing.

Expected behavior

The generated binary should print:

1
42

matching PHP.

Actual behavior

The delegated generator appears to run incorrectly once its return value is captured via yield from, and the outer generator produces no visible output.

Environment

  • elephc 0.21.14
  • PHP 8.4.20
  • macOS ARM64

Notes

This looks separate from type inference issues around yield / send(). The failure here is runtime behavior after successful compilation.

Likely areas:

  • generator lowering / resume-state handling for yield from
  • propagation of the delegated generator's terminal return value into the outer generator frame
  • codegen/runtime interaction for delegation completion

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggeneratorsGenerators and yieldphp-compatibilityPHP compatibility / deviation from PHP behaviorruntimeRuntime library / GC / ownership

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions