Skip to content

Commit e163f8a

Browse files
Add test
1 parent eb2f23a commit e163f8a

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ private static function findTestFiles(): iterable
8888
yield __DIR__ . '/../Rules/Variables/data/bug-10577.php';
8989
yield __DIR__ . '/../Rules/Variables/data/bug-10610.php';
9090
yield __DIR__ . '/../Rules/Comparison/data/bug-2550.php';
91+
yield __DIR__ . '/../Rules/Comparison/data/bug-12412.php';
9192
yield __DIR__ . '/../Rules/Properties/data/bug-3777.php';
9293
yield __DIR__ . '/../Rules/Methods/data/bug-4552.php';
9394
yield __DIR__ . '/../Rules/Methods/data/infer-array-key.php';

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,4 +999,10 @@ public function testBug12755(): void
999999
$this->analyse([__DIR__ . '/data/bug-12755.php'], []);
10001000
}
10011001

1002+
public function testBug12412(): void
1003+
{
1004+
$this->treatPhpDocTypesAsCertain = true;
1005+
$this->analyse([__DIR__ . '/data/bug-12412.php'], []);
1006+
}
1007+
10021008
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12412;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @param 'A'|'B' $type
9+
* @return list<string>
10+
*/
11+
function f(string $type): array {
12+
$field_list = [ ];
13+
if ($type === 'A') {
14+
array_push($field_list, 'x1');
15+
}
16+
if ($type === 'B') {
17+
array_push($field_list, 'x2');
18+
}
19+
20+
assertType('bool', in_array('x1', $field_list, true));
21+
22+
array_push($field_list, 'x3');
23+
assertType('bool', in_array('x1', $field_list, true));
24+
25+
return $field_list;
26+
}

0 commit comments

Comments
 (0)