Skip to content

Commit d4bfc70

Browse files
committed
PropertyReflectionFinder - fixed #2745
1 parent 2b0013f commit d4bfc70

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/Rules/Properties/PropertyReflectionFinder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public function findPropertyReflectionFromNode($propertyFetch, Scope $scope): ?F
4545

4646
private function findPropertyReflection(Type $propertyHolderType, string $propertyName, Scope $scope, bool $fetchedOnThis): ?FoundPropertyReflection
4747
{
48-
if (!$propertyHolderType->hasProperty($propertyName)->yes()) {
49-
return null;
50-
}
51-
5248
$transformedPropertyHolderType = TypeTraverser::map($propertyHolderType, static function (Type $type, callable $traverse) use ($scope, $fetchedOnThis): Type {
5349
if ($type instanceof StaticType) {
5450
if ($fetchedOnThis && $scope->isInClass()) {
@@ -62,6 +58,10 @@ private function findPropertyReflection(Type $propertyHolderType, string $proper
6258
return $traverse($type);
6359
});
6460

61+
if (!$transformedPropertyHolderType->hasProperty($propertyName)->yes()) {
62+
return null;
63+
}
64+
6565
$originalProperty = $transformedPropertyHolderType->getProperty($propertyName, $scope);
6666
$readableType = $this->transformPropertyType($originalProperty->getReadableType(), $transformedPropertyHolderType, $scope, $fetchedOnThis);
6767
$writableType = $this->transformPropertyType($originalProperty->getWritableType(), $transformedPropertyHolderType, $scope, $fetchedOnThis);

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ public function testCollectWarnings(): void
189189
$this->assertSame(PHP_VERSION_ID >= 70400 ? 22 : 27, $errors[0]->getLine());
190190
}
191191

192+
public function testPropertyAssignIntersectionStaticTypeBug(): void
193+
{
194+
$errors = $this->runAnalyse(__DIR__ . '/data/property-assign-intersection-static-type-bug.php');
195+
$this->assertCount(0, $errors);
196+
}
197+
192198
/**
193199
* @param string $file
194200
* @return \PHPStan\Analyser\Error[]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace PropertyAssignIntersectionStaticTypeBug;
4+
5+
abstract class Base
6+
{
7+
/** @var string */
8+
private $foo;
9+
10+
public function __construct(string $foo)
11+
{
12+
\assert($this instanceof Frontend || $this instanceof Backend);
13+
14+
$this->foo = $foo;
15+
}
16+
}
17+
18+
class Frontend extends Base
19+
{
20+
21+
}
22+
23+
class Backend extends Base
24+
{
25+
26+
}

0 commit comments

Comments
 (0)