File tree Expand file tree Collapse file tree
tests/PHPStan/Rules/Functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -542,6 +542,29 @@ public function testBug11507(): void
542542 $ this ->analyse ([__DIR__ . '/data/bug-11507.php ' ], []);
543543 }
544544
545+ public function testBug6567 (): void
546+ {
547+ $ this ->checkNullables = true ;
548+ $ this ->checkExplicitMixed = false ;
549+ $ this ->analyse ([__DIR__ . '/data/bug-6567.php ' ], [
550+ [
551+ 'Function Bug6567\add() should return T of int but returns int. ' ,
552+ 11 ,
553+ 'Type int is not always the same as T. It breaks the contract for some argument types, typically subtypes. ' ,
554+ ],
555+ [
556+ 'Function Bug6567\testBool() should return T of bool but returns false. ' ,
557+ 27 ,
558+ 'Type false is not always the same as T. It breaks the contract for some argument types, typically subtypes. ' ,
559+ ],
560+ [
561+ 'Function Bug6567\testFloat() should return T of float but returns float. ' ,
562+ 36 ,
563+ 'Type float is not always the same as T. It breaks the contract for some argument types, typically subtypes. ' ,
564+ ],
565+ ]);
566+ }
567+
545568 public function testBug15245 (): void
546569 {
547570 $ this ->checkNullables = true ;
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug6567 ;
4+
5+ /**
6+ * @template T of int
7+ * @param T $p
8+ * @return T
9+ */
10+ function add ($ p ) {
11+ return $ p + 1000 ;
12+ }
13+
14+ /**
15+ * @param int<0,100> $p
16+ */
17+ function test ($ p ): void {
18+ \PHPStan \dumpType (add ($ p ));
19+ }
20+
21+ /**
22+ * @template T of bool
23+ * @param T $p
24+ * @return T
25+ */
26+ function testBool ($ p ) {
27+ return false ;
28+ }
29+
30+ /**
31+ * @template T of float
32+ * @param T $p
33+ * @return T
34+ */
35+ function testFloat ($ p ) {
36+ return $ p + 1 ;
37+ }
You can’t perform that action at this time.
0 commit comments