diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index fc84b105f..d0ea11670 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -48,20 +48,22 @@ class CastAnalyzer if ($maybe_type) { if ($maybe_type->isInt()) { - if ($maybe_type->from_docblock) { - $issue = new RedundantCastGivenDocblockType( - 'Redundant cast to ' . $maybe_type->getKey() . ' given docblock-provided type', - new CodeLocation($statements_analyzer->getSource(), $stmt) - ); - } else { - $issue = new RedundantCast( - 'Redundant cast to ' . $maybe_type->getKey(), - new CodeLocation($statements_analyzer->getSource(), $stmt) - ); - } + if (!$maybe_type->from_calculation) { + if ($maybe_type->from_docblock) { + $issue = new RedundantCastGivenDocblockType( + 'Redundant cast to ' . $maybe_type->getKey() . ' given docblock-provided type', + new CodeLocation($statements_analyzer->getSource(), $stmt) + ); + } else { + $issue = new RedundantCast( + 'Redundant cast to ' . $maybe_type->getKey(), + new CodeLocation($statements_analyzer->getSource(), $stmt) + ); + } - if (IssueBuffer::accepts($issue, $statements_analyzer->getSuppressedIssues())) { - // fall through + if (IssueBuffer::accepts($issue, $statements_analyzer->getSuppressedIssues())) { + // fall through + } } } diff --git a/tests/TypeReconciliation/RedundantConditionTest.php b/tests/TypeReconciliation/RedundantConditionTest.php index 25e7b3ead..f1de64ba5 100644 --- a/tests/TypeReconciliation/RedundantConditionTest.php +++ b/tests/TypeReconciliation/RedundantConditionTest.php @@ -791,6 +791,12 @@ class RedundantConditionTest extends \Psalm\Tests\TestCase } }' ], + 'noRedundantCastAfterCalculation' => [ + '