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
4 changes: 4 additions & 0 deletions src/Type/Generic/TemplateTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ public function traverseSimultaneously(Type $right, callable $cb): Type

public function tryRemove(Type $typeToRemove): ?Type
{
if ($typeToRemove instanceof TemplateType) {
return null;
}

$bound = TypeCombinator::remove($this->getBound(), $typeToRemove);
if ($this->getBound() === $bound) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,10 @@ public function testBug13676(): void
$this->analyse([__DIR__ . '/data/bug-13676.php'], []);
}

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

}
51 changes: 51 additions & 0 deletions tests/PHPStan/Rules/TooWideTypehints/data/bug-11430.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php // lint >= 8.2

declare(strict_types = 1);

namespace Bug11430;

/**
* @template T
*/
interface Option {}

/**
* @template T
* @implements Option<T>
*/
class Some implements Option
{
/**
* @param T $value
*/
public function __construct(public mixed $value) {}
}

/**
* @implements Option<never>
*/
class None implements Option {}

/**
* @internal
*/
final class Choice
{
/**
* @template T
* @template S
*
* @param T $value
* @param S $none
*
* @return (T is S ? None : Some<T>)
*/
public static function from(mixed $value, mixed $none = null): Option
{
if ($value === $none) {
return new None();
}

return new Some($value);
}
}
Loading