Skip to content

Commit 883f637

Browse files
authored
Merge branch refs/heads/1.11.x into 1.12.x
2 parents d401944 + 708d938 commit 883f637

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

src/Type/ArrayType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,9 +541,7 @@ public function intersectKeyArray(Type $otherArraysType): Type
541541
}
542542

543543
if ($isKeySuperType->yes()) {
544-
return $otherArraysType->isIterableAtLeastOnce()->yes()
545-
? TypeCombinator::intersect($this, new NonEmptyArrayType())
546-
: $this;
544+
return $this;
547545
}
548546

549547
return new self($otherArraysType->getIterableKeyType(), $this->getIterableValueType());

tests/PHPStan/Analyser/nsrt/array-intersect-key.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class Foo
1515
public function nonEmpty(array $arr, array $arr2): void
1616
{
1717
assertType('non-empty-array<int|string, string>', array_intersect_key($arr));
18-
assertType('non-empty-array<int|string, string>', array_intersect_key($arr, $arr));
18+
assertType('array<int|string, string>', array_intersect_key($arr, $arr));
1919
assertType('array<int, string>', array_intersect_key($arr, $arr2));
20-
assertType('non-empty-array<int, string>', array_intersect_key($arr2, $arr));
20+
assertType('array<int, string>', array_intersect_key($arr2, $arr));
2121
assertType('array{}', array_intersect_key($arr, []));
2222
assertType("array<'foo', string>", array_intersect_key($arr, ['foo' => 17]));
2323
}

tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,10 @@ public function testBug2499(): void
162162
$this->analyse([__DIR__ . '/data/bug-2499.php'], []);
163163
}
164164

165+
public function testBug10561(): void
166+
{
167+
$this->treatPhpDocTypesAsCertain = true;
168+
$this->analyse([__DIR__ . '/data/bug-10561.php'], []);
169+
}
170+
165171
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Bug10561;
4+
5+
/**
6+
* @param mixed[] $arr1
7+
* @param mixed[] $arr2
8+
*/
9+
function func(array $arr1, array $arr2): void {
10+
11+
/** @var array<string, string> $inner_arr1 */
12+
$inner_arr1 = $arr1['inner_arr'];
13+
/** @var array<string, string> $inner_arr2 */
14+
$inner_arr2 = $arr2['inner_arr'];
15+
16+
if (!$inner_arr1) {
17+
return;
18+
}
19+
if (!$inner_arr2) {
20+
return;
21+
}
22+
23+
$arr_intersect = array_intersect_key($inner_arr1, $inner_arr2);
24+
if ($arr_intersect) {
25+
echo "not empty\n";
26+
} else {
27+
echo "empty\n";
28+
}
29+
}
30+
31+
$arr1 = ['inner_arr' => ['a' => 'b']];
32+
$arr2 = ['inner_arr' => ['c' => 'd']];
33+
func($arr1, $arr2); // Outputs "empty"

0 commit comments

Comments
 (0)