Skip to content

A generator's raw-typed by-ref param loses the lazy write when the caller's variable is an undefined (vivified) local. #187

Closed

Description

@blacktrs

Summary

A generator's raw-typed by-ref param loses the lazy write when the caller's variable is an undefined (vivified) local.

Repro

<?php
function gen(?array &$r = null) { $r = [1]; yield 1; }
function h() { foreach (gen($y) as $v) { echo count($y), $v, "\n"; } }
h();

Expected (php)

11

Actual (manticore 1c706498, Darwin arm64)

01

Tracking

Known-bug repro: tests/aot/repro/wrong/generator_raw_byref_param_vivified_cell.php — bash tests/aot/xfail.sh -k generator_raw_byref_param_vivified_cell reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    needs-design
    area:refs
    on Oct 11, 2026
  2. blacktrs commented on Oct 13, 2026

    @blacktrs
    ContributorAuthor

    Scope: heap ref-box for generator by-ref params. A vivified out-variable is a cell slot and the call site uses the scratch-and-rebox path (emitByRefCellUnboxArg), which writes the scratch back when the call returns. A generator writes its parameter lazily at first resume, by which time the scratch is a dead stack slot. Fix: back the generator's by-ref param with a heap ref box. The same laziness hole exists in the reverse direction (a raw caller local passed to a cell param). Found in batch E; skipped.

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:refsbugneeds-designwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions