-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix type aliases in method-level template types
- Loading branch information
1 parent
e5e48ea
commit c926144
Showing
3 changed files
with
78 additions
and
2 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,69 @@ | ||
<?php | ||
|
||
namespace Bug9008; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class A {} | ||
class B {} | ||
class C {} | ||
|
||
/** @phpstan-type Alpha A|B|C */ | ||
class Example | ||
{ | ||
/** | ||
* @template TypeAlpha of Alpha | ||
* @param TypeAlpha $alpha | ||
* @phpstan-return TypeAlpha | ||
*/ | ||
public function shouldWorkOne(object $alpha): object | ||
{ | ||
assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::shouldWorkOne(), argument)', $alpha); | ||
return $alpha; | ||
} | ||
|
||
/** | ||
* @template TypeAlpha of Alpha | ||
* @param TypeAlpha $alpha | ||
* @phpstan-return TypeAlpha | ||
*/ | ||
public function shouldWorkTwo(object $alpha): object | ||
{ | ||
assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::shouldWorkTwo(), argument)', $alpha); | ||
return $alpha; | ||
} | ||
|
||
/** | ||
* @template TypeAlpha of A|B|C | ||
* @param TypeAlpha $alpha | ||
* @phpstan-return TypeAlpha | ||
*/ | ||
public function worksButExtraVerboseOne(object $alpha): object | ||
{ | ||
assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::worksButExtraVerboseOne(), argument)', $alpha); | ||
return $alpha; | ||
} | ||
|
||
/** | ||
* @template TypeAlpha of A|B|C | ||
* @param TypeAlpha $alpha | ||
* @phpstan-return TypeAlpha | ||
*/ | ||
public function worksButExtraVerboseTwo(object $alpha): object | ||
{ | ||
assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::worksButExtraVerboseTwo(), argument)', $alpha); | ||
return $alpha; | ||
} | ||
|
||
/** | ||
* @param Alpha $alpha | ||
*/ | ||
public function test(object $alpha): void | ||
{ | ||
assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $alpha); | ||
assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->shouldWorkOne($alpha)); | ||
assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->shouldWorkTwo($alpha)); | ||
assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->worksButExtraVerboseOne($alpha)); | ||
assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->worksButExtraVerboseTwo($alpha)); | ||
} | ||
} |