Skip to content

Commit 8134126

Browse files
committed
1 parent 4730f04 commit 8134126

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

‎tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)