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
16 changes: 16 additions & 0 deletions src/Type/Generic/TemplateTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@

$callSiteVariance = $callSiteVariances->getVariance($type->getName());
if ($callSiteVariance === null || $callSiteVariance->invariant()) {
if (
$newType instanceof TemplateType
&& $newType->getName() === $type->getName()
&& $newType->getScope()->equals($type->getScope())
&& !$type->getBound()->equals($newType->getBound())
&& $newType->getBound()->isSuperTypeOf($type->getBound())->yes()

Check warning on line 62 in src/Type/Generic/TemplateTypeHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ && $newType->getName() === $type->getName() && $newType->getScope()->equals($type->getScope()) && !$type->getBound()->equals($newType->getBound()) - && $newType->getBound()->isSuperTypeOf($type->getBound())->yes() + && !$newType->getBound()->isSuperTypeOf($type->getBound())->no() ) { return TemplateTypeFactory::create( $newType->getScope(),

Check warning on line 62 in src/Type/Generic/TemplateTypeHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ && $newType->getName() === $type->getName() && $newType->getScope()->equals($type->getScope()) && !$type->getBound()->equals($newType->getBound()) - && $newType->getBound()->isSuperTypeOf($type->getBound())->yes() + && $type->getBound()->isSuperTypeOf($newType->getBound())->yes() ) { return TemplateTypeFactory::create( $newType->getScope(),

Check warning on line 62 in src/Type/Generic/TemplateTypeHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\TrinaryLogicMutator": @@ @@ && $newType->getName() === $type->getName() && $newType->getScope()->equals($type->getScope()) && !$type->getBound()->equals($newType->getBound()) - && $newType->getBound()->isSuperTypeOf($type->getBound())->yes() + && !$newType->getBound()->isSuperTypeOf($type->getBound())->no() ) { return TemplateTypeFactory::create( $newType->getScope(),

Check warning on line 62 in src/Type/Generic/TemplateTypeHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Escaped Mutant for Mutator "PHPStan\Infection\IsSuperTypeOfCalleeAndArgumentMutator": @@ @@ && $newType->getName() === $type->getName() && $newType->getScope()->equals($type->getScope()) && !$type->getBound()->equals($newType->getBound()) - && $newType->getBound()->isSuperTypeOf($type->getBound())->yes() + && $type->getBound()->isSuperTypeOf($newType->getBound())->yes() ) { return TemplateTypeFactory::create( $newType->getScope(),
) {
return TemplateTypeFactory::create(
$newType->getScope(),
$newType->getName(),
$type->getBound(),
$newType->getVariance(),
$newType->getStrategy(),
$newType->getDefault(),
);
}
return $newType;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11776.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php // lint >= 8.2

declare(strict_types=1);

namespace Bug11776;

use function PHPStan\Testing\assertType;

/**
* @template TOperation of int|string
*/
interface EnumAsFilterInterface {}

/**
* @template TOperation of scalar
*/
final readonly class ScalarableChoice
{
/**
* @param class-string<EnumAsFilterInterface<(int|string)&TOperation>> $choiceClassName
*/
public function __construct(private string $choiceClassName) {}

/**
* @return class-string<EnumAsFilterInterface<(int|string)&TOperation>>
*/
public function getChoiceClassName(): string
{
assertType('class-string<Bug11776\EnumAsFilterInterface<TOperation of int|string (class Bug11776\ScalarableChoice, argument)>>', $this->choiceClassName);
return $this->choiceClassName;
}
}
Loading