Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsRes
static fn (Type $innerType) => $acceptingType->accepts($innerType, $strictTypes),
);

if ($result->yes()) {
$isSuperType = $acceptingType->isSuperTypeOf($this);
if ($isSuperType->no()) {
return $isSuperType->toAcceptsResult();
}
}

if ($this->isOversizedArray()->yes()) {
if (!$result->no()) {
return AcceptsResult::createYes();
Expand Down
37 changes: 37 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4017,4 +4017,41 @@ public function testBug13272(): void
$this->analyse([__DIR__ . '/data/bug-13272.php'], []);
}

public function testBug14549(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-14549-bis.php'], [
[
'Parameter #1 $param of method Bug14549Bis\Foo::callArrayInt() expects array<int>, array&callable given.',
33,
],
[
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayStringString() expects array{string, string}, array&callable(): mixed given.',
34,
],
[
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayObjectOrStringStringString() expects array{object|string, string, string}, array&callable(): mixed given.',
36,
],
[
'Parameter #1 $param of method Bug14549Bis\Foo::callArrayInt() expects array<int>, array&callable given.',
44,
],
[
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayStringString() expects array{string, string}, array&callable(): mixed given.',
45,
],
[
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayObjectOrStringStringString() expects array{object|string, string, string}, array&callable(): mixed given.',
47,
],
[
'Parameter #1 $param of method Bug14549Bis\Foo::callArrayString() expects array<string>, array given.',
58,
],
]);
}

}
63 changes: 63 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-14549-bis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Bug14549Bis;

class Foo
{

/** @param array<int> $param */
public function callArrayInt(array $param): void
{
}

/** @param array{string, string} $param */
public function callConstantArrayStringString(array $param): void
{
}

/** @param array{object|string, string} $param */
public function callConstantArrayObjectOrStringString(array $param): void
{
}

/** @param array{object|string, string, string} $param */
public function callConstantArrayObjectOrStringStringString(array $param): void
{
}

/**
* @param callable-array $task
*/
public function doCallWithCallableArray(array $task): void
{
$this->callArrayInt($task);
$this->callConstantArrayStringString($task);
$this->callConstantArrayObjectOrStringString($task);
$this->callConstantArrayObjectOrStringStringString($task);
}

/**
* @param callable&array $task
*/
public function doCallWithCallableAndArray(array $task): void
{
$this->callArrayInt($task);
$this->callConstantArrayStringString($task);
$this->callConstantArrayObjectOrStringString($task);
$this->callConstantArrayObjectOrStringStringString($task);
}

/** @param array<string> $param */
public function callArrayString(array $param): void
{
}

public function doCallWithHasOffsetValue(array $arr): void
{
if (isset($arr[1]) && $arr[1] === 1) {
$this->callArrayString($arr);
$this->callArrayInt($arr);
}
}

}
Loading