1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix reconciliation of ored types

This commit is contained in:
Matthew Brown 2018-05-13 00:54:12 -04:00
parent 69338abf7c
commit 9f28be415a
3 changed files with 57 additions and 1 deletions

View File

@ -105,7 +105,7 @@ class Reconciler
foreach ($new_type_part_parts as $new_type_part_part) {
$result_type_candidate = self::reconcileTypes(
$new_type_part_part,
$result_type,
$result_type ? clone $result_type : null,
$key,
$statements_checker,
$code_location && isset($referenced_var_ids[$key]) ? $code_location : null,

View File

@ -364,6 +364,51 @@ class SwitchTypeTest extends TestCase
}
}',
],
'switchNullable1' => [
'<?php
function foo(?string $s) : void {
switch ($s) {
case "hello":
case "goodbye":
echo "cool";
break;
case "hello again":
echo "cool";
break;
}
}',
],
'switchNullable2' => [
'<?php
function foo(?string $s) : void {
switch ($s) {
case "hello":
echo "cool";
case "goodbye":
echo "cooler";
break;
case "hello again":
echo "cool";
break;
}
}',
],
'switchNullable3' => [
'<?php
function foo(?string $s) : void {
switch ($s) {
case "hello":
echo "cool";
break;
case "goodbye":
echo "cool";
break;
case "hello again":
echo "cool";
break;
}
}',
],
];
}

View File

@ -786,6 +786,17 @@ class TypeReconciliationTest extends TestCase
}
}'
],
'reconcileNullableStringWithWeakEquality' => [
'<?php
function foo(?string $s) : void {
if ($s == "hello" || $s == "goodbye") {
if ($s == "hello") {
echo "cool";
}
echo "cooler";
}
}',
],
];
}