diff --git a/src/Rules/Comparison/ImpossibleCheckTypeHelper.php b/src/Rules/Comparison/ImpossibleCheckTypeHelper.php index 43d2532c98..a49038600a 100644 --- a/src/Rules/Comparison/ImpossibleCheckTypeHelper.php +++ b/src/Rules/Comparison/ImpossibleCheckTypeHelper.php @@ -170,6 +170,10 @@ public function findSpecifiedType( return true; } + if ($expr instanceof Expr\Variable && is_string($expr->name) && !$scope->hasVariableType($expr->name)->yes()) { + return true; + } + return ( $node instanceof FuncCall || $node instanceof MethodCall diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php index 5a471e0a19..8e7633a5df 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php @@ -406,4 +406,11 @@ public function testBug4657(): void $this->analyse([__DIR__ . '/data/bug-4657.php'], []); } + public function testBug4999(): void + { + $this->checkAlwaysTrueCheckTypeFunctionCall = true; + $this->treatPhpDocTypesAsCertain = false; + $this->analyse([__DIR__ . '/data/bug-4999.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-4999.php b/tests/PHPStan/Rules/Comparison/data/bug-4999.php new file mode 100644 index 0000000000..ee2af8c7f6 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-4999.php @@ -0,0 +1,25 @@ +