forked from phpstan/phpstan-src
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug-12847.php
69 lines (56 loc) · 1.19 KB
/
bug-12847.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php declare(strict_types = 1);
namespace Bug12847;
function doBar():void {
/**
* @var array<mixed> $array
*/
$array = [
'abc' => 'def'
];
if (isset($array['def'])) {
doSomething($array);
}
}
function doFoo(array $array):void {
if (isset($array['def'])) {
doSomething($array);
}
}
function doFooBar(array $array):void {
if (array_key_exists('foo', $array) && $array['foo'] === 17) {
doSomething($array);
}
}
function doImplicitMixed($mixed):void {
if (isset($mixed['def'])) {
doSomething($mixed);
}
}
function doExplicitMixed(mixed $mixed): void
{
if (isset($mixed['def'])) {
doSomething($mixed);
}
}
/**
* @param non-empty-array<mixed> $array
*/
function doSomething(array $array): void
{
}
/**
* @param non-empty-array<int> $array
*/
function doSomethingWithInt(array $array): void
{
}
function doFooBarInt(array $array):void {
if (array_key_exists('foo', $array) && $array['foo'] === 17) {
doSomethingWithInt($array); // expect error, because our array is not sealed
}
}
function doFooBarString(array $array):void {
if (array_key_exists('foo', $array) && $array['foo'] === "hello") {
doSomethingWithInt($array); // expect error, because our array is not sealed
}
}