Skip to content

Commit 5365444

Browse files
Fix intersection with substracted
1 parent 5878035 commit 5365444

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Type/TypeCombinator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ private static function unionWithSubtractedType(
544544
$subtractedType = $type->getSubtractedType() === null
545545
? $subtractedType
546546
: self::union($type->getSubtractedType(), $subtractedType);
547+
548+
$subtractedType = self::intersect(
549+
$type->getTypeWithoutSubtractedType(),
550+
$subtractedType,
551+
);
547552
if ($subtractedType instanceof NeverType) {
548553
$subtractedType = null;
549554
}

tests/PHPStan/Type/TypeCombinatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,6 +4127,22 @@ public static function dataIntersect(): iterable
41274127
IntersectionType::class,
41284128
'lowercase-string&uppercase-string',
41294129
],
4130+
[
4131+
[
4132+
new ObjectType(DateTime::class),
4133+
new MixedType(subtractedType: new NullType()),
4134+
],
4135+
ObjectType::class,
4136+
'DateTime',
4137+
],
4138+
[
4139+
[
4140+
new ObjectWithoutClassType(),
4141+
new MixedType(subtractedType: new NullType()),
4142+
],
4143+
ObjectWithoutClassType::class,
4144+
'object',
4145+
],
41304146
];
41314147

41324148
if (PHP_VERSION_ID < 80100) {

0 commit comments

Comments
 (0)