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

Prevent duplicate switch return types

This commit is contained in:
Brown 2020-09-25 09:45:20 -04:00
parent ea08e0c613
commit c17bacd682
2 changed files with 16 additions and 1 deletions

View File

@ -268,7 +268,7 @@ class ScopeAnalyzer
}
if ($has_default_terminator || isset($stmt->allMatched)) {
return array_merge($control_actions, [self::ACTION_END]);
return \array_values(array_unique(array_merge($control_actions, [self::ACTION_END])));
}
}

View File

@ -984,6 +984,21 @@ class SwitchTypeTest extends TestCase
return true;
}'
],
'alwaysReturnsWithConditionalReturnFirst' => [
'<?php
function getRows(string $s) : int {
if (rand(0, 1)) {
return 1;
}
switch ($s) {
case "a":
return 2;
default:
return 1;
}
}'
],
];
}