|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bug9008; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +class A {} |
| 8 | +class B {} |
| 9 | +class C {} |
| 10 | + |
| 11 | +/** @phpstan-type Alpha A|B|C */ |
| 12 | +class Example |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @template TypeAlpha of Alpha |
| 16 | + * @param TypeAlpha $alpha |
| 17 | + * @phpstan-return TypeAlpha |
| 18 | + */ |
| 19 | + public function shouldWorkOne(object $alpha): object |
| 20 | + { |
| 21 | + assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::shouldWorkOne(), argument)', $alpha); |
| 22 | + return $alpha; |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @template TypeAlpha of Alpha |
| 27 | + * @param TypeAlpha $alpha |
| 28 | + * @phpstan-return TypeAlpha |
| 29 | + */ |
| 30 | + public function shouldWorkTwo(object $alpha): object |
| 31 | + { |
| 32 | + assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::shouldWorkTwo(), argument)', $alpha); |
| 33 | + return $alpha; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @template TypeAlpha of A|B|C |
| 38 | + * @param TypeAlpha $alpha |
| 39 | + * @phpstan-return TypeAlpha |
| 40 | + */ |
| 41 | + public function worksButExtraVerboseOne(object $alpha): object |
| 42 | + { |
| 43 | + assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::worksButExtraVerboseOne(), argument)', $alpha); |
| 44 | + return $alpha; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @template TypeAlpha of A|B|C |
| 49 | + * @param TypeAlpha $alpha |
| 50 | + * @phpstan-return TypeAlpha |
| 51 | + */ |
| 52 | + public function worksButExtraVerboseTwo(object $alpha): object |
| 53 | + { |
| 54 | + assertType('TypeAlpha of Bug9008\A|Bug9008\B|Bug9008\C (method Bug9008\Example::worksButExtraVerboseTwo(), argument)', $alpha); |
| 55 | + return $alpha; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * @param Alpha $alpha |
| 60 | + */ |
| 61 | + public function test(object $alpha): void |
| 62 | + { |
| 63 | + assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $alpha); |
| 64 | + assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->shouldWorkOne($alpha)); |
| 65 | + assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->shouldWorkTwo($alpha)); |
| 66 | + assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->worksButExtraVerboseOne($alpha)); |
| 67 | + assertType('Bug9008\\A|Bug9008\\B|Bug9008\\C', $this->worksButExtraVerboseTwo($alpha)); |
| 68 | + } |
| 69 | +} |
0 commit comments