diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index b3affb3f0..20f87bd55 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -2016,22 +2016,15 @@ class AssertionFinder return; } - $always_contains = TypeAnalyzer::isContainedBy( - $codebase, - $expected_type, - $first_var_type - ); - - $never_contains = !TypeAnalyzer::isContainedBy( + if (!TypeAnalyzer::isContainedBy( $codebase, $first_var_type, $expected_type - ); + )) { + return; + } - /** @psalm-suppress ParadoxicalCondition */ - if (($always_contains && !$negate) - || ($never_contains && $negate) - ) { + if (!$negate) { if ($first_var_type->from_docblock) { if (IssueBuffer::accepts( new RedundantConditionGivenDocblockType( @@ -2053,9 +2046,7 @@ class AssertionFinder // fall through } } - } elseif (($always_contains && $negate) - || ($never_contains && !$negate) - ) { + } else { if ($first_var_type->from_docblock) { if (IssueBuffer::accepts( new DocblockTypeContradiction( diff --git a/src/Psalm/Internal/Analyzer/TypeAnalyzer.php b/src/Psalm/Internal/Analyzer/TypeAnalyzer.php index 0a5b036c5..c42369e9f 100644 --- a/src/Psalm/Internal/Analyzer/TypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/TypeAnalyzer.php @@ -1047,7 +1047,7 @@ class TypeAnalyzer } if ($container_type_part instanceof TNumeric && - ($input_type_part->isNumericType() || $input_type_part instanceof TString) + $input_type_part->isNumericType() ) { return true; } diff --git a/tests/TypeCombinationTest.php b/tests/TypeCombinationTest.php index ad2889992..865d0677f 100644 --- a/tests/TypeCombinationTest.php +++ b/tests/TypeCombinationTest.php @@ -188,7 +188,7 @@ class TypeCombinationTest extends TestCase ], ], 'arrayMixedOrStringKeys' => [ - 'array', + 'array', [ 'array', 'array', diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index d49a054cc..d8f0547d5 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -816,7 +816,7 @@ class TypeParseTest extends TestCase */ public function testVeryLargeType() { - $very_large_type = 'array{a: Closure():(array|null), b?: Closure():array, c?: Closure():array, d?: Closure():array, e?: Closure():(array{f: null|string, g: null|string, h: null|string, i: string, j: mixed, k: mixed, l: mixed, m: mixed, n: bool, o?: array{0: string}}|null), p?: Closure():(array{f: null|string, g: null|string, h: null|string, i: string, j: mixed, k: mixed, l: mixed, m: mixed, n: bool, o?: array{0: string}}|null), q: string, r?: Closure():(array|null), s: array}|null'; + $very_large_type = 'array{a: Closure():(array|null), b?: Closure():array, c?: Closure():array, d?: Closure():array, e?: Closure():(array{f: null|string, g: null|string, h: null|string, i: string, j: mixed, k: mixed, l: mixed, m: mixed, n: bool, o?: array{0: string}}|null), p?: Closure():(array{f: null|string, g: null|string, h: null|string, i: string, j: mixed, k: mixed, l: mixed, m: mixed, n: bool, o?: array{0: string}}|null), q: string, r?: Closure():(array|null), s: array}|null'; $this->assertSame( $very_large_type, diff --git a/tests/TypeReconciliation/ReconcilerTest.php b/tests/TypeReconciliation/ReconcilerTest.php index 9477d8a36..f4cf67171 100644 --- a/tests/TypeReconciliation/ReconcilerTest.php +++ b/tests/TypeReconciliation/ReconcilerTest.php @@ -59,9 +59,7 @@ class ReconcilerTest extends \Psalm\Tests\TestCase $reconciled->getId() ); - if (is_array($reconciled->getAtomicTypes())) { - $this->assertContainsOnlyInstancesOf('Psalm\Type\Atomic', $reconciled->getAtomicTypes()); - } + $this->assertContainsOnlyInstancesOf('Psalm\Type\Atomic', $reconciled->getAtomicTypes()); } /** diff --git a/tests/TypeReconciliation/RedundantConditionTest.php b/tests/TypeReconciliation/RedundantConditionTest.php index 96a61ea25..59c3c712e 100644 --- a/tests/TypeReconciliation/RedundantConditionTest.php +++ b/tests/TypeReconciliation/RedundantConditionTest.php @@ -773,6 +773,16 @@ class RedundantConditionTest extends \Psalm\Tests\TestCase '$fp' => 'closed-resource', ] ], + 'allowCheckOnReturnTypeUnion' => [ + ' 'RedundantCondition', ], + 'preventAlwaysReturningSpecificInt' => [ + ' 'RedundantConditionGivenDocblockType', + ], + 'preventNotAlwaysReturningInt' => [ + ' 'TypeDoesNotContainType', + ], ]; } }