diff --git a/src/Type/ObjectShapePropertyReflection.php b/src/Type/ObjectShapePropertyReflection.php index 1d022cb726..a5c64c126c 100644 --- a/src/Type/ObjectShapePropertyReflection.php +++ b/src/Type/ObjectShapePropertyReflection.php @@ -61,12 +61,12 @@ public function getPhpDocType(): Type public function hasNativeType(): bool { - return false; + return true; } public function getNativeType(): Type { - return new MixedType(); + return $this->type; } public function getReadableType(): Type diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index 99f7ed3dd9..77c1a594d7 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -1019,6 +1019,16 @@ public function testBug10884(): void $this->analyse([__DIR__ . '/data/bug-10884.php'], []); } + public function testBug11609(): void + { + $this->analyse([__DIR__ . '/data/bug-11609.php'], [ + [ + 'Strict comparison using !== between string and null will always evaluate to true.', + 16, + ], + ]); + } + public function testBug3761(): void { $this->analyse([__DIR__ . '/data/bug-3761.php'], []); diff --git a/tests/PHPStan/Rules/Comparison/data/bug-11609.php b/tests/PHPStan/Rules/Comparison/data/bug-11609.php new file mode 100644 index 0000000000..537640c199 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-11609.php @@ -0,0 +1,20 @@ +hello !== null) { // should report notIdentical.alwaysTrue + echo 'hello'; + } + if (isset($a->world)) { // shouldn't report any error + echo 'world'; + } + if ($b !== null) { + echo 'b'; + } + } +}