Skip to content

MIR.verify ownflow fails on a local assigned from require in one branch and an array in the other #537

Closed

Description

@samdark

A local that gets the result of require in one branch and an array parameter in the other fails MIR.verify when it is read after the if.

<?php
final class Settings
{
    public array $packages;

    public function __construct(string $path, array $composerExtra)
    {
        if (isset($composerExtra['config-file'])) {
            /** @var array $extra */
            $extra = require $path . '/' . $composerExtra['config-file'];
        } else {
            $extra = $composerExtra;
        }
        $this->packages = (array) ($extra['packages'] ?? []);
    }
}
file_put_contents('/tmp/extra.php', '<?php return ["packages" => ["a" => 1]];');
var_dump((new Settings('/tmp', ['config-file' => 'extra.php']))->packages);
var_dump((new Settings('/tmp', ['packages' => ['b' => 2]]))->packages);

Expected (php):

array(1) {
  ["a"]=>
  int(1)
}
array(1) {
  ["b"]=>
  int(2)
}

Actual (manticore compile req.php -o req):

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

Casting both assignments to (array) makes it compile. The same pattern is in yiisoft/config (Composer/ConfigSettings::__construct). A similar case there, $result = $this->buildGroup(...) / $result = $this->merger->merge(...) in a loop inside Config::buildGroup, fails with (arr vs scalar).

Manticore 0.17.0 (ghcr.io/manticorephp/compiler:latest, image built 2026-10-24, Linux x86_64). PHP reference: 8.5.4.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. added theissue type on Oct 30, 2026
  3. added
    area:types
    on Oct 30, 2026
  4. blacktrs commented on Oct 30, 2026

    @blacktrs
    Contributor

    Thanks for a great repro and the package reference. It will help fix the issue faster.

    The analyzer, in this specific case, currently cannot guess the real type from the require result. It will probably be complicated, but it seems possible to fix.

    Explicit casting should help for now.

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:typesbug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions