Skip to content

Commit 692d510

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents dde8da5 + 0e10531 commit 692d510

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Type/CallableType.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,14 @@ private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny): IsSup
171171
return $isCallable;
172172
}
173173

174+
$parameterTypes = array_map(static fn ($parameter) => $parameter->getType(), $this->getParameters());
175+
174176
$variantsResult = null;
175177
foreach ($type->getCallableParametersAcceptors($scope) as $variant) {
178+
$variant = ParametersAcceptorSelector::selectFromTypes($parameterTypes, [$variant], false);
179+
if (!$variant instanceof CallableParametersAcceptor) {
180+
return IsSuperTypeOfResult::createNo([]);
181+
}
176182
$isSuperType = CallableTypeHelper::isParametersAcceptorSuperTypeOf($this, $variant, $treatMixedAsAny);
177183
if ($variantsResult === null) {
178184
$variantsResult = $isSuperType;

src/Type/ClosureType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,14 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
211211
private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny): IsSuperTypeOfResult
212212
{
213213
if ($type instanceof self) {
214+
$parameterTypes = array_map(static fn ($parameter) => $parameter->getType(), $this->getParameters());
215+
$variant = ParametersAcceptorSelector::selectFromTypes($parameterTypes, [$type], false);
216+
if (!$variant instanceof CallableParametersAcceptor) {
217+
return IsSuperTypeOfResult::createNo([]);
218+
}
214219
return CallableTypeHelper::isParametersAcceptorSuperTypeOf(
215220
$this,
216-
$type,
221+
$variant,
217222
$treatMixedAsAny,
218223
);
219224
}

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,6 +3519,16 @@ public function testBug12544(): void
35193519
]);
35203520
}
35213521

3522+
public function testBug12691(): void
3523+
{
3524+
$this->checkThisOnly = false;
3525+
$this->checkNullables = true;
3526+
$this->checkUnionTypes = true;
3527+
$this->checkExplicitMixed = true;
3528+
3529+
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-12691.php'], []);
3530+
}
3531+
35223532
public function testBug12422(): void
35233533
{
35243534
if (PHP_VERSION_ID < 80100) {

0 commit comments

Comments
 (0)