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

Suppress enum redundant conditions too

This commit is contained in:
Matthew Brown 2018-05-20 18:58:34 -04:00
parent 3805893c5a
commit 19ca1c9311
2 changed files with 22 additions and 0 deletions

View File

@ -278,6 +278,10 @@ class SwitchChecker
$statements_checker->addSuppressedIssues(['RedundantCondition']);
}
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
$statements_checker->addSuppressedIssues(['RedundantConditionGivenDocblockType']);
}
$case_vars_in_scope_reconciled =
Reconciler::reconcileKeyedTypes(
$reconcilable_if_types,
@ -297,6 +301,10 @@ class SwitchChecker
$statements_checker->removeSuppressedIssues(['RedundantCondition']);
}
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
$statements_checker->removeSuppressedIssues(['RedundantConditionGivenDocblockType']);
}
$case_context->vars_in_scope = $case_vars_in_scope_reconciled;
foreach ($reconcilable_if_types as $var_id => $_) {
$case_context->vars_possibly_in_scope[$var_id] = true;

View File

@ -35,6 +35,20 @@ class EnumTest extends TestCase
foo(2);
foo(3);',
],
'noRedundantConditionWithSwitch' => [
'<?php
/**
* @psalm-param ( "foo" | "bar") $s
*/
function foo(string $s) : void {
switch ($s) {
case "foo":
break;
case "bar":
break;
}
}',
],
];
}