Skip to content

Inserting keys while a foreach iterates a Manticore\Ds\Map never throws, so the loop runs away #398

Closed

Description

@blacktrs

Summary

Inserting keys while a foreach iterates a Manticore\Ds\Map never throws, so the loop runs away.

Repro

<?php
use Manticore\Ds\Map;
$m = new Map();
$m->set('a', 1);
$n = 0;
try {
    foreach ($m as $k => $v) {
        $n++;
        if ($n > 1000) { echo "runaway\n"; break; }
        $m->set('k' . $n, $n);
    }
    echo "finished\n";
} catch (\RuntimeException $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

Expected (php)

RuntimeException: Map modified during iteration

Actual (manticore 515a500a, Darwin arm64)

runaway
finished

Tracking

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

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

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions