1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix strict isset reconciliation

This commit is contained in:
Matt Brown 2018-05-07 17:15:27 -04:00
parent 6460d907f9
commit 2299cecd23
2 changed files with 41 additions and 1 deletions

View File

@ -782,7 +782,7 @@ class Reconciler
);
}
if ($new_var_type === 'isset' || $new_var_type === 'array-key-exists') {
if (!$is_strict_equality && ($new_var_type === 'isset' || $new_var_type === 'array-key-exists')) {
return Type::getNull();
}

View File

@ -326,6 +326,46 @@ class TypeAlgebraTest extends TestCase
}
}',
],
'moreConvolutedArrayCreation' => [
'<?php
function fetchRow() : array {
return ["c" => "UK"];
}
$arr = [];
foreach ([1, 2, 3] as $i) {
$row = fetchRow();
if (!isset($arr[$row["c"]])) {
$arr[$row["c"]] = 0;
}
$arr[$row["c"]] = 1;
}',
'assertions' => [],
'error_levels' => ['MixedArrayOffset'],
],
'moreConvolutedNestedArrayCreation' => [
'<?php
function fetchRow() : array {
return ["c" => "UK"];
}
$arr = [];
foreach ([1, 2, 3] as $i) {
$row = fetchRow();
if (!isset($arr[$row["c"]]["foo"])) {
$arr[$row["c"]]["foo"] = 0;
}
$arr[$row["c"]]["foo"] = 1;
}',
'assertions' => [],
'error_levels' => ['MixedArrayOffset'],
],
'noParadoxInLoop' => [
'<?php
function paradox2(): void {