Skip to content

Commit

Permalink
Fix of weird bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 2, 2022
1 parent 0fc7699 commit 843ebbb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\Generic\TemplateUnionType;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
use PHPStan\Type\Traits\NonRemoveableTypeTrait;
use function array_map;
Expand Down Expand Up @@ -131,8 +132,8 @@ public function isSubTypeOf(Type $otherType): TrinaryLogic

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
{
if ($acceptingType instanceof self || $acceptingType instanceof UnionType) {
return $acceptingType->isSuperTypeOf($this);
if ($acceptingType instanceof self || ($acceptingType instanceof UnionType && !$acceptingType instanceof TemplateUnionType)) {
return $acceptingType->accepts($this, $strictTypes);
}

$results = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic
return TrinaryLogic::createYes();
}

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

Expand Down
27 changes: 27 additions & 0 deletions tests/PHPStan/Rules/Methods/data/call-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -1802,3 +1802,30 @@ public function test(): void
$this->foo('Newark Liberty International');
}
}

class WeirdArrayBug
{

/** @param string[] $strings */
public function doBar($m, array $a, bool $b, array $strings)
{
$needles = [$m];
foreach ($a as $v) {
if ($b) {
$needles = array_merge($needles, $strings);
}
}

$this->doFoo($needles);
}

/**
* @param array<string>|string $strings
* @return void
*/
public function doFoo($strings)
{

}

}

0 comments on commit 843ebbb

Please sign in to comment.