File tree Expand file tree Collapse file tree 6 files changed +81
-0
lines changed
Expand file tree Collapse file tree 6 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 33namespace PHPStan \Type \Generic ;
44
55use PHPStan \Type \BenevolentUnionType ;
6+ use PHPStan \Type \NeverType ;
67use PHPStan \Type \Type ;
78
89/** @api */
@@ -50,6 +51,9 @@ public function withTypes(array $types): self
5051 public function filterTypes (callable $ filterCb ): Type
5152 {
5253 $ result = parent ::filterTypes ($ filterCb );
54+ if ($ result instanceof NeverType) {
55+ return $ result ;
56+ }
5357 if (!$ result instanceof TemplateType) {
5458 return TemplateTypeFactory::create (
5559 $ this ->getScope (),
Original file line number Diff line number Diff line change 22
33namespace PHPStan \Type \Generic ;
44
5+ use PHPStan \Type \NeverType ;
56use PHPStan \Type \Type ;
67use PHPStan \Type \UnionType ;
78
@@ -37,6 +38,9 @@ public function __construct(
3738 public function filterTypes (callable $ filterCb ): Type
3839 {
3940 $ result = parent ::filterTypes ($ filterCb );
41+ if ($ result instanceof NeverType) {
42+ return $ result ;
43+ }
4044 if (!$ result instanceof TemplateType) {
4145 return TemplateTypeFactory::create (
4246 $ this ->getScope (),
Original file line number Diff line number Diff line change @@ -209,4 +209,9 @@ public function testBug12119(): void
209209 $ this ->analyse ([__DIR__ . '/data/bug-12119.php ' ], []);
210210 }
211211
212+ public function testBug14504 (): void
213+ {
214+ $ this ->analyse ([__DIR__ . '/data/bug-14504.php ' ], []);
215+ }
216+
212217}
Original file line number Diff line number Diff line change @@ -377,4 +377,10 @@ public function testBug12382(): void
377377 ]);
378378 }
379379
380+ public function testBug14504 (): void
381+ {
382+ $ this ->treatPhpDocTypesAsCertain = true ;
383+ $ this ->analyse ([__DIR__ . '/data/bug-14504-method.php ' ], []);
384+ }
385+
380386}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug14504Method ;
4+
5+ /**
6+ * @template T of int|string
7+ */
8+ class Foo
9+ {
10+
11+ /** @param T $val */
12+ public function __construct (private $ val ) {}
13+
14+ /** @phpstan-pure */
15+ public function toString (): string {
16+ return (string )$ this ->val ;
17+ }
18+
19+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug14504 ;
4+
5+ /**
6+ * @phpstan-pure
7+ * @template T of int|string
8+ * @param T $val
9+ * @return string
10+ */
11+ function stringCast ($ val ): string {
12+ return (string )$ val ;
13+ }
14+
15+ /**
16+ * @phpstan-pure
17+ * @template T of int|string
18+ * @param T $val
19+ * @return string
20+ */
21+ function stringConcat ($ val ): string {
22+ return '' . $ val ;
23+ }
24+
25+ /**
26+ * @phpstan-pure
27+ * @template T of int|string
28+ * @param T $val
29+ * @return string
30+ */
31+ function stringInterpolation ($ val ): string {
32+ return "$ val " ;
33+ }
34+
35+ /**
36+ * @phpstan-pure
37+ * @template T of int|float|bool
38+ * @param T $val
39+ * @return string
40+ */
41+ function nonStringNonObjectCast ($ val ): string {
42+ return (string )$ val ;
43+ }
You can’t perform that action at this time.
0 commit comments