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
8 changes: 4 additions & 4 deletions src/Type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
return $type->isAcceptedBy($this, $strictTypes);
}

return $this->isSuperTypeOfInternal($type, true)->toAcceptsResult();
return $this->isSuperTypeOfInternal($type, true, $strictTypes)->toAcceptsResult();
}

public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
Expand All @@ -147,10 +147,10 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
return $type->isSubTypeOf($this);
}

return $this->isSuperTypeOfInternal($type, false);
return $this->isSuperTypeOfInternal($type, false, true);
}

private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny): IsSuperTypeOfResult
private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny, bool $strictTypes): IsSuperTypeOfResult
{
$isCallable = new IsSuperTypeOfResult($type->isCallable(), []);
if ($isCallable->no()) {
Expand Down Expand Up @@ -183,7 +183,7 @@ private function isSuperTypeOfInternal(Type $type, bool $treatMixedAsAny): IsSup
if (!$variant instanceof CallableParametersAcceptor) {
return IsSuperTypeOfResult::createNo([]);
}
$isSuperType = CallableTypeHelper::isParametersAcceptorSuperTypeOf($this, $variant, $treatMixedAsAny);
$isSuperType = CallableTypeHelper::isParametersAcceptorSuperTypeOf($this, $variant, $treatMixedAsAny, $strictTypes);
if ($variantsResult === null) {
$variantsResult = $isSuperType;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/Type/CallableTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static function isParametersAcceptorSuperTypeOf(
CallableParametersAcceptor $ours,
CallableParametersAcceptor $theirs,
bool $treatMixedAsAny,
bool $strictTypes = true,
): IsSuperTypeOfResult
{
$theirParameters = $theirs->getParameters();
Expand Down Expand Up @@ -72,7 +73,7 @@ public static function isParametersAcceptorSuperTypeOf(
}

if ($treatMixedAsAny) {
$isSuperType = $theirParameter->getType()->accepts($ourParameterType, true);
$isSuperType = $theirParameter->getType()->accepts($ourParameterType, $strictTypes);
$isSuperType = new IsSuperTypeOfResult($isSuperType->result, $isSuperType->reasons);
} else {
$isSuperType = $theirParameter->getType()->isSuperTypeOf($ourParameterType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2746,4 +2746,10 @@ public function testBug13247(): void
$this->analyse([__DIR__ . '/data/bug-13247.php'], []);
}

#[RequiresPhp('>= 8.1')]
public function testBug11619(): void
{
$this->analyse([__DIR__ . '/data/bug-11619.php'], []);
}

}
30 changes: 30 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-11619.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php // lint >= 8.1

namespace Bug11619;

final class Foo implements \Stringable {

private function __construct(public readonly string $value) {
}

public static function fromString(string $string): self {
return new self($string);
}

public function __toString(): string {
return $this->value;
}

}

function test(): void
{
$options = [
Foo::fromString('c'),
Foo::fromString('b'),
Foo::fromString('a'),
];

uasort($options, 'strnatcasecmp');
usort($options, 'strnatcasecmp');
}
Loading