Skip to content

Commit 0d7fe19

Browse files
committed
Normalize decimal-int-string intersection with lowercase-string/uppercase-string
1 parent e38383a commit 0d7fe19

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/Type/Accessory/AccessoryDecimalIntegerStringType.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
124124
return $otherType->isSuperTypeOf($this);
125125
}
126126

127-
if ($otherType instanceof AccessoryNumericStringType && !$this->inverse) {
127+
if (
128+
(
129+
$otherType instanceof AccessoryNumericStringType
130+
|| $otherType instanceof AccessoryLowercaseStringType
131+
|| $otherType instanceof AccessoryUppercaseStringType
132+
)
133+
&& !$this->inverse
134+
) {
128135
return IsSuperTypeOfResult::createYes();
129136
}
130137

@@ -357,12 +364,12 @@ public function isLiteralString(): TrinaryLogic
357364

358365
public function isLowercaseString(): TrinaryLogic
359366
{
360-
return TrinaryLogic::createMaybe();
367+
return $this->inverse ? TrinaryLogic::createMaybe() : TrinaryLogic::createYes();
361368
}
362369

363370
public function isUppercaseString(): TrinaryLogic
364371
{
365-
return TrinaryLogic::createMaybe();
372+
return $this->inverse ? TrinaryLogic::createMaybe() : TrinaryLogic::createYes();
366373
}
367374

368375
public function isClassString(): TrinaryLogic

tests/PHPStan/Type/TypeCombinatorTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,6 +2874,24 @@ public static function dataUnion(): iterable
28742874
StringType::class,
28752875
'string',
28762876
];
2877+
2878+
yield [
2879+
[
2880+
$decimalIntString,
2881+
new IntersectionType([new StringType(), new AccessoryLowercaseStringType()]),
2882+
],
2883+
IntersectionType::class,
2884+
'lowercase-string',
2885+
];
2886+
2887+
yield [
2888+
[
2889+
$nonDecimalIntString,
2890+
new IntersectionType([new StringType(), new AccessoryLowercaseStringType()]),
2891+
],
2892+
StringType::class,
2893+
'string',
2894+
];
28772895
}
28782896

28792897
/**
@@ -5024,6 +5042,29 @@ public static function dataIntersect(): iterable
50245042
NeverType::class,
50255043
'*NEVER*=implicit',
50265044
];
5045+
5046+
yield [
5047+
[
5048+
$decimalIntString,
5049+
new IntersectionType([
5050+
new StringType(),
5051+
new AccessoryLowercaseStringType(),
5052+
]),
5053+
],
5054+
IntersectionType::class,
5055+
'decimal-int-string',
5056+
];
5057+
yield [
5058+
[
5059+
$nonDecimalIntString,
5060+
new IntersectionType([
5061+
new StringType(),
5062+
new AccessoryLowercaseStringType(),
5063+
]),
5064+
],
5065+
IntersectionType::class,
5066+
'lowercase-string&non-decimal-int-string',
5067+
];
50275068
}
50285069

50295070
/**

0 commit comments

Comments
 (0)