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

Improve solution to allow for more user errors

This commit is contained in:
Matthew Brown 2017-03-11 12:32:27 -05:00
parent 39b9afcdac
commit a7da88bad3
3 changed files with 20 additions and 8 deletions

View File

@ -588,11 +588,19 @@ class IfChecker
}
if ($negated_elseif_types) {
$negated_keys = [];
foreach ($negated_elseif_types as $var_id => $type) {
if (!$has_leaving_statements || $type !== '!empty') {
$negated_keys[] = $var_id;
}
}
$outer_context->update(
$old_elseif_context,
$elseif_context,
$has_leaving_statements,
array_keys($negated_elseif_types),
$negated_keys,
$if_scope->updated_vars
);
}

View File

@ -284,6 +284,8 @@ class Union
foreach ($new_type->types as $key => $new_type_part) {
$this->types[$key] = $new_type_part;
}
} elseif (count($this->types) === 0) {
$this->types['mixed'] = new Atomic\TMixed();
}
}

View File

@ -862,22 +862,24 @@ class TypeReconciliationTest extends PHPUnit_Framework_TestCase
/**
* @return void
*/
public function testEmptyArrayReconciliationThenElseif()
public function testEmptyStringReconciliationThenIf()
{
$stmts = self::$parser->parse('<?php
/**
* @param string|string[] $a
* @param Exception|string|string[] $a
*/
function foo($a) : string {
if (is_string($a)) {
return $a;
if (is_array($a)) {
return "hello";
} elseif (empty($a)) {
return "goodbye";
} elseif (isset($a[0])) {
return $a[0];
}
if (is_string($a)) {
return $a;
};
return "not found";
return "an exception";
}
');