1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Make sure weak equality clauses don’t generate ParadoxicalCondition

This commit is contained in:
Matthew Brown 2018-05-13 01:27:45 -04:00
parent 9f28be415a
commit d46997b196
3 changed files with 35 additions and 1 deletions

View File

@ -155,7 +155,9 @@ class Algebra
[$var => [$type]],
false,
true,
$type[0] === '^' || (strlen($type) > 1 && $type[1] === '^')
$type[0] === '^'
|| $type[0] === '~'
|| (strlen($type) > 1 && ($type[1] === '^' || $type[1] === '~'))
);
}
}

View File

@ -409,6 +409,16 @@ class SwitchTypeTest extends TestCase
}
}',
],
'switchNullable4' => [
'<?php
function foo(?string $s, string $a, string $b) : void {
switch ($s) {
case $a:
case $b:
break;
}
}',
],
];
}

View File

@ -797,6 +797,28 @@ class TypeReconciliationTest extends TestCase
}
}',
],
'reconcileNullableStringWithStrictEqualityStrings' => [
'<?php
function foo(?string $s, string $a, string $b) : void {
if ($s === $a || $s === $b) {
if ($s === $a) {
echo "cool";
}
echo "cooler";
}
}',
],
'reconcileNullableStringWithWeakEqualityStrings' => [
'<?php
function foo(?string $s, string $a, string $b) : void {
if ($s == $a || $s == $b) {
if ($s == $a) {
echo "cool";
}
echo "cooler";
}
}',
],
];
}