Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/Type/NeverType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
use PHPStan\Type\Traits\NonGenericTypeTrait;
use PHPStan\Type\Traits\NonRemoveableTypeTrait;
Expand Down Expand Up @@ -81,6 +82,10 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
return IsSuperTypeOfResult::createYes();
}

if ($type instanceof TemplateType) {
return IsSuperTypeOfResult::createMaybe();
}

return IsSuperTypeOfResult::createNo();
}

Expand Down
6 changes: 6 additions & 0 deletions src/Type/NonAcceptingNeverType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPStan\Type;

use PHPStan\Type\Generic\TemplateType;

/** @api */
class NonAcceptingNeverType extends NeverType
{
Expand All @@ -21,6 +23,10 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
return IsSuperTypeOfResult::createMaybe();
}

if ($type instanceof TemplateType) {
return IsSuperTypeOfResult::createMaybe();
}

return IsSuperTypeOfResult::createNo();
}

Expand Down
29 changes: 29 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-9634.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types = 1);

namespace Bug9634;

use function PHPStan\Testing\assertType;

/** @template T */
interface Option {
/** @return self<never> */
static function none(): self;

/** @return T */
function unwrap(): mixed;

/**
* @return (T is never ? false : bool)
*/
function isSome(): bool;
}

/** @param Option<never> $o */
function f(Option $o): void {
assertType('false', $o->isSome());
}

/** @param Option<int> $o */
function g(Option $o): void {
assertType('bool', $o->isSome());
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ public function testBug11939(): void
$this->analyse([__DIR__ . '/data/bug-11939.php'], []);
}

public function testBug9634(): void
{
$this->analyse([__DIR__ . '/data/bug-9634.php'], []);
}

}
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-9634.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Bug9634;

/** @template T */
interface Option {
/** @return self<never> */
static function none(): self;

/** @return T */
function unwrap(): mixed;

/**
* @return (T is never ? false : bool)
*/
function isSome(): bool;
}

/** @param Option<never> $o */
function f(Option $o): true {
return $o->isSome();
}
Loading