Skip to content

Commit b0b9a20

Browse files
Update ObjectShape native type
1 parent e0c4844 commit b0b9a20

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/Type/ObjectShapePropertyReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ public function getPhpDocType(): Type
6161

6262
public function hasNativeType(): bool
6363
{
64-
return false;
64+
return true;
6565
}
6666

6767
public function getNativeType(): Type
6868
{
69-
return new MixedType();
69+
return $this->type;
7070
}
7171

7272
public function getReadableType(): Type

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,16 @@ public function testBug10884(): void
10191019
$this->analyse([__DIR__ . '/data/bug-10884.php'], []);
10201020
}
10211021

1022+
public function testBug11609(): void
1023+
{
1024+
$this->analyse([__DIR__ . '/data/bug-11609.php'], [
1025+
[
1026+
'Strict comparison using !== between string and null will always evaluate to true.',
1027+
16,
1028+
],
1029+
]);
1030+
}
1031+
10221032
public function testBug3761(): void
10231033
{
10241034
$this->analyse([__DIR__ . '/data/bug-3761.php'], []);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11609;
4+
5+
class HelloWorld
6+
{
7+
/** @param object{hello: string, world?: string} $a */
8+
public function sayHello(object $a, string $b): void
9+
{
10+
if ($a->hello !== null) { // should report notIdentical.alwaysTrue
11+
echo 'hello';
12+
}
13+
if (isset($a->world)) { // shouldn't report any error
14+
echo 'world';
15+
}
16+
if ($b !== null) {
17+
echo 'b';
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)