mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Ignore redundant conditions inside match potentially in perpetuity?
This commit is contained in:
parent
b785efb210
commit
9b726904f9
@ -110,10 +110,28 @@ class MatchAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
$suppressed_issues = $statements_analyzer->getSuppressedIssues();
|
||||
|
||||
if (!in_array('RedundantCondition', $suppressed_issues, true)) {
|
||||
$statements_analyzer->addSuppressedIssues(['RedundantCondition']);
|
||||
}
|
||||
|
||||
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
|
||||
$statements_analyzer->addSuppressedIssues(['RedundantConditionGivenDocblockType']);
|
||||
}
|
||||
|
||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $ternary, $context) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!in_array('RedundantCondition', $suppressed_issues, true)) {
|
||||
$statements_analyzer->removeSuppressedIssues(['RedundantCondition']);
|
||||
}
|
||||
|
||||
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
|
||||
$statements_analyzer->removeSuppressedIssues(['RedundantConditionGivenDocblockType']);
|
||||
}
|
||||
|
||||
if ($stmt_expr_type = $statements_analyzer->node_data->getType($ternary)) {
|
||||
$old_node_data->setType($stmt, $stmt_expr_type ?: Type::getMixed());
|
||||
}
|
||||
|
@ -43,6 +43,19 @@ class MatchTest extends TestCase
|
||||
[],
|
||||
'8.0'
|
||||
],
|
||||
'allMatchedNoRedundantCondition' => [
|
||||
'<?php
|
||||
function foo() : string {
|
||||
$a = rand(0, 1) ? "a" : "b";
|
||||
return match ($a) {
|
||||
"a" => "hello",
|
||||
"b" => "goodbye",
|
||||
};
|
||||
}',
|
||||
[],
|
||||
[],
|
||||
'8.0'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -83,6 +96,36 @@ class MatchTest extends TestCase
|
||||
false,
|
||||
'8.0'
|
||||
],
|
||||
'allMatchedDefaultImpossible' => [
|
||||
'<?php
|
||||
function foo() : string {
|
||||
$a = rand(0, 1) ? "a" : "b";
|
||||
return match ($a) {
|
||||
"a" => "hello",
|
||||
"b" => "goodbye",
|
||||
default => "impossible",
|
||||
};
|
||||
}',
|
||||
'error_message' => 'TypeDoesNotContainType',
|
||||
[],
|
||||
false,
|
||||
'8.0'
|
||||
],
|
||||
'allMatchedAnotherImpossible' => [
|
||||
'<?php
|
||||
function foo() : string {
|
||||
$a = rand(0, 1) ? "a" : "b";
|
||||
return match ($a) {
|
||||
"a" => "hello",
|
||||
"b" => "goodbye",
|
||||
"c" => "impossible",
|
||||
};
|
||||
}',
|
||||
'error_message' => 'TypeDoesNotContainType',
|
||||
[],
|
||||
false,
|
||||
'8.0'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user