mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix reconciliation of non-isset array vars
This commit is contained in:
parent
c6ed1b0458
commit
091d13b73f
@ -59,8 +59,8 @@ class Reconciler
|
||||
CodeLocation $code_location = null,
|
||||
array $suppressed_issues = []
|
||||
) {
|
||||
foreach ($new_types as $nk => $_) {
|
||||
if (strpos($nk, '[')) {
|
||||
foreach ($new_types as $nk => $type) {
|
||||
if (strpos($nk, '[') && ($type === '^isset' || $type === '!^empty')) {
|
||||
$path_parts = self::breakUpPathIntoParts($nk);
|
||||
|
||||
if (count($path_parts) > 1) {
|
||||
|
@ -153,15 +153,58 @@ class ValueTest extends TestCase
|
||||
takesInt($i);
|
||||
}',
|
||||
],
|
||||
'regularStringComparison' => [
|
||||
'regularComparison1' => [
|
||||
'<?php
|
||||
function foo(string $s1, string $s2) : string {
|
||||
function foo(string $s1, string $s2, ?int $i) : string {
|
||||
if ($s1 !== $s2) {
|
||||
return $s1;
|
||||
}
|
||||
|
||||
return $s2;
|
||||
}',
|
||||
],
|
||||
'regularComparison2' => [
|
||||
'<?php
|
||||
function foo(string $s1, string $s2) : string {
|
||||
if ($s1 !== "hello") {
|
||||
if ($s1 !== "goodbye") {
|
||||
return $s1;
|
||||
}
|
||||
}
|
||||
|
||||
return $s2;
|
||||
}',
|
||||
],
|
||||
'regularComparison3' => [
|
||||
'<?php
|
||||
class A {
|
||||
const B = 1;
|
||||
const C = 2;
|
||||
|
||||
}
|
||||
function foo(string $s1, string $s2, ?int $i) : string {
|
||||
if ($i !== A::B && $i !== A::C) {}
|
||||
|
||||
return $s2;
|
||||
}',
|
||||
],
|
||||
'regularComparisonOnPossiblyNull' => [
|
||||
'<?php
|
||||
/** @psalm-ignore-nullable-return */
|
||||
function generate() : ?string {
|
||||
return rand(0, 1000) ? "hello" : null;
|
||||
}
|
||||
|
||||
function foo() : string {
|
||||
$str = generate();
|
||||
|
||||
if ($str[0] === "h") {
|
||||
return $str;
|
||||
}
|
||||
|
||||
return "hello";
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user