Skip to content

A foreach value variable reassigned from an array element inside try fails MIR.verify ownflow (cell vs mixdead) #156

Closed

Description

@blacktrs

Summary

A foreach value variable reassigned from an array element inside try fails MIR.verify ownflow (cell vs mixdead).

Repro

<?php
function save(array $x, int $l): bool|array { return $l > 5 ? [] : true; }
function commit(array $values, array $by): int {
    $n = 0;
    foreach ($values as $id => $v) {
        $n += (int) $v;
    }
    foreach ($by as $lifetime => $ids) {
        foreach ($ids as $id => $unused) {
            try {
                $v = $by[$lifetime][$id];
                $e = save([$id => $v], $lifetime);
            } catch (\Exception $e) {
            }
            if (true === $e) { continue; }
            echo get_debug_type($v), "\n";
        }
    }
    return $n;
}
echo commit(['a' => 1, 'b' => 'z'], [1 => ['k' => 'v'], 9 => ['q' => 3]]), "\n";

Expected (php)

int
1

Actual (manticore 7f55d99b, Darwin arm64)

compile failed (rc=65):
compile failed: MIR.verify: ownflow: $v read at line 17 in commit past a representation mismatch (cell vs mixdead): the name is live there
compile: front-end (parse/typeck/IR) returned null (rc=65)

Tracking

Known-bug repro: tests/aot/repro/crash/foreach_var_reassigned_in_try_ownflow_mismatch.php — bash tests/aot/xfail.sh -k foreach_var_reassigned_in_try_ownflow_mismatch 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
    crash
    on Oct 9, 2026
  2. blacktrs commented on Oct 9, 2026

    @blacktrs
    ContributorAuthor

    Partly fixed (foreach var whose cell store is outside its own loop; closure/bool merges; erased-array alias beside a concrete store). Remaining in symfony: CachePoolPass::process (#160), Dotenv::loadEnv (edge never reached its target), Caster::castObject ($k cell vs scalar).

  3. blacktrs commented on Oct 9, 2026

    @blacktrs
    ContributorAuthor

    Update: Dotenv::loadEnv (nested try/finally inside a finally stole the outer finally's deferred return — Forward::tryCatch keyed owners by depth) is fixed too. Left in symfony: CachePoolPass::process (#160) and Caster::castObject ($k: int-keyed foreach key = Scalar vs cell-keyed loops = Borrow(cell) in one slot).

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

    bugcrash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions