Skip to content

Commit 843ebbb

Browse files
committed
Fix of weird bug
1 parent 0fc7699 commit 843ebbb

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/Type/IntersectionType.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPStan\Type\Generic\TemplateType;
2323
use PHPStan\Type\Generic\TemplateTypeMap;
2424
use PHPStan\Type\Generic\TemplateTypeVariance;
25+
use PHPStan\Type\Generic\TemplateUnionType;
2526
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
2627
use PHPStan\Type\Traits\NonRemoveableTypeTrait;
2728
use function array_map;
@@ -131,8 +132,8 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic
131132

132133
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
133134
{
134-
if ($acceptingType instanceof self || $acceptingType instanceof UnionType) {
135-
return $acceptingType->isSuperTypeOf($this);
135+
if ($acceptingType instanceof self || ($acceptingType instanceof UnionType && !$acceptingType instanceof TemplateUnionType)) {
136+
return $acceptingType->accepts($this, $strictTypes);
136137
}
137138

138139
$results = [];

src/Type/UnionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic
9595
return TrinaryLogic::createYes();
9696
}
9797

98-
if ($type instanceof CompoundType && !$type instanceof CallableType && !$type instanceof TemplateType) {
98+
if ($type instanceof CompoundType && !$type instanceof CallableType && !$type instanceof TemplateType && !$type instanceof IntersectionType) {
9999
return $type->isAcceptedBy($this, $strictTypes);
100100
}
101101

tests/PHPStan/Rules/Methods/data/call-methods.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,3 +1802,30 @@ public function test(): void
18021802
$this->foo('Newark Liberty International');
18031803
}
18041804
}
1805+
1806+
class WeirdArrayBug
1807+
{
1808+
1809+
/** @param string[] $strings */
1810+
public function doBar($m, array $a, bool $b, array $strings)
1811+
{
1812+
$needles = [$m];
1813+
foreach ($a as $v) {
1814+
if ($b) {
1815+
$needles = array_merge($needles, $strings);
1816+
}
1817+
}
1818+
1819+
$this->doFoo($needles);
1820+
}
1821+
1822+
/**
1823+
* @param array<string>|string $strings
1824+
* @return void
1825+
*/
1826+
public function doFoo($strings)
1827+
{
1828+
1829+
}
1830+
1831+
}

0 commit comments

Comments
 (0)