mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Improve solution to allow for more user errors
This commit is contained in:
parent
39b9afcdac
commit
a7da88bad3
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
}
|
||||
');
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user