psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Crash when iterating iterable checked with instanceof

Open AndrolGenhald opened this issue 2 years ago • 1 comments

This works fine: https://psalm.dev/r/cf4d41e75e This crashes: https://psalm.dev/r/a315359995

Presumably this is because the instanceof check results in a TNamedObject instead of TGenericObject, but it should really work either way.

(see also #8292)

AndrolGenhald avatar Jul 20 '22 20:07 AndrolGenhald

I found these snippets:

https://psalm.dev/r/cf4d41e75e
<?php

/** @var iterable */
$foo = [];

/** @psalm-trace $foo */;

foreach ($foo as $value) {
}
Psalm output (using commit 85fe7e8):

INFO: Trace - 6:25 - $foo: iterable<mixed, mixed>

INFO: MixedAssignment - 8:18 - Unable to determine the type that $value is being assigned to

INFO: UnusedForeachValue - 8:18 - $value is never referenced or the value is not used
https://psalm.dev/r/0fd9a8b4ff
<?php

/** @var mixed */
$foo = null;

if (!$foo instanceof iterable) {
    throw new \Exception();
}

/** @psalm-trace $foo */;

// foreach ($foo as $key => $value) {
// }
Psalm output (using commit 85fe7e8):

INFO: Trace - 10:25 - $foo: iterable
https://psalm.dev/r/a315359995
<?php

/** @var mixed */
$foo = null;

if (!$foo instanceof iterable) {
    throw new \Exception();
}

foreach ($foo as $key => $value) {
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for iterable

psalm-github-bot[bot] avatar Jul 20 '22 20:07 psalm-github-bot[bot]

Seems fixed

orklah avatar Oct 21 '22 05:10 orklah