-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix wrong positives about templates in conditional types
- Loading branch information
Showing
7 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Bug8609TypeInference; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @template T of bool | ||
*/ | ||
class Foo | ||
{ | ||
|
||
/** @return (T is true ? 'foo' : 'bar') */ | ||
public function doFoo(): string | ||
{ | ||
|
||
} | ||
|
||
} | ||
|
||
class Bar | ||
{ | ||
|
||
/** | ||
* @param Foo<true> $f | ||
* @param Foo<false> $g | ||
* @param Foo<bool> $h | ||
* @param Foo $i | ||
*/ | ||
public function doFoo(Foo $f, Foo $g, Foo $h, Foo $i): void | ||
{ | ||
assertType('\'foo\'', $f->doFoo()); | ||
assertType('\'bar\'', $g->doFoo()); | ||
assertType('\'bar\'|\'foo\'', $h->doFoo()); | ||
assertType('\'bar\'|\'foo\'', $i->doFoo()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Bug8609Function; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* @template T of list<string>|list<list<string>> | ||
* @param T $bar | ||
* | ||
* @return (T[0] is string ? array{T} : T) | ||
*/ | ||
function foo(array $bar) : array{ return is_string($bar[0]) ? [$bar] : $bar; } | ||
|
||
function(): void { | ||
assertType('array{array{string, string}}', foo(['foo', 'bar'])); | ||
assertType('array{array{string, string}, array{string, string}}', foo([['foo','bar'],['xyz','asd']])); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\PhpDoc\data; | ||
|
||
/** | ||
* @template T of int | ||
*/ | ||
class A { | ||
/** @var T */ | ||
private $value; | ||
|
||
/** @param T $value */ | ||
public function __construct($value) { | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @template C of int | ||
* | ||
* @param C $coefficient | ||
* | ||
* @return ( | ||
* T is positive-int | ||
* ? (C is positive-int ? positive-int : negative-int) | ||
* : T is negative-int | ||
* ? (C is positive-int ? negative-int : positive-int) | ||
* : (T is 0 ? 0 : int) | ||
* ) | ||
* ) | ||
*/ | ||
public function multiply(int $coefficient): int { | ||
return $this->value * $coefficient; | ||
} | ||
} |