Skip to content

Commit 0814669

Browse files
committed
Allow to override property union type with @property tag subtype
1 parent c5d17f8 commit 0814669

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ private function createProperty(
451451
if (
452452
$hierarchyDistances[$annotationProperty->getDeclaringClass()->getName()] <= $hierarchyDistances[$distanceDeclaringClass]
453453
) {
454+
if ($nativeType->isSuperTypeOf($annotationProperty->getReadableType())->yes()) {
455+
$nativeType = new MixedType();
456+
}
457+
454458
return new PhpPropertyReflection(
455459
$annotationProperty->getDeclaringClass(),
456460
$declaringTrait,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace OverridePropertyUnionTypeWithTagSubtype;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public function __construct(
10+
public readonly ?int $hello,
11+
) {
12+
}
13+
}
14+
15+
/** @property int $hello */
16+
final class HelloWorld2 extends HelloWorld
17+
{
18+
public function __construct(
19+
int $hello
20+
) {
21+
parent::__construct(hello: $hello);
22+
}
23+
}
24+
25+
function hello2(HelloWorld2 $bla): void
26+
{
27+
assertType('int', $bla->hello);
28+
}

0 commit comments

Comments
 (0)