Skip to content

Commit 7b60a47

Browse files
committed
Fix ArrayColumnHelper for non-empty-list<array<string, mixed>> to return also non-empty-list
1 parent c0f2e9e commit 7b60a47

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/Type/Php/ArrayColumnHelper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public function getReturnValueType(Type $arrayType, Type $columnType, Scope $sco
4343

4444
if ($returnValueType === null) {
4545
$returnValueType = $this->getOffsetOrProperty($iterableValueType, $columnType, $scope, true);
46-
$iterableAtLeastOnce = TrinaryLogic::createMaybe();
46+
47+
// if (TypeCombinator::contains($arrayType, new NonEmptyArrayType())) {
48+
// $iterableAtLeastOnce = TrinaryLogic::createYes();
49+
// } else {
50+
// $iterableAtLeastOnce = TrinaryLogic::createMaybe();
51+
// }
52+
4753
if ($returnValueType === null) {
4854
throw new ShouldNotHappenException();
4955
}

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ public function testBug3379(): void
272272
$this->assertSame('Constant SOME_UNKNOWN_CONST not found.', $errors[0]->getMessage());
273273
}
274274

275+
public function testArraysBug(): void
276+
{
277+
$errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-array-column.php');
278+
$this->assertNoErrors($errors);
279+
}
280+
275281
public function testBug3798(): void
276282
{
277283
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3798.php');

tests/PHPStan/Analyser/nsrt/array-column.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ public function testObjects2(array $array): void
239239
assertType('non-empty-array<DOMElement>', array_column($array, null, 'foo'));
240240
}
241241

242+
/**
243+
* @param non-empty-list<array<string, mixed>> $list
244+
*/
245+
public function testList1(array $list): void
246+
{
247+
assertType('non-empty-list<mixed>', array_column($list, 'value'));
248+
}
242249
}
243250

244251
final class Foo
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php // lint < 8.2
2+
3+
namespace ArrayColumn;
4+
5+
use DOMElement;
6+
use function PHPStan\Testing\assertType;
7+
8+
9+
class ArrayColumnTest
10+
{
11+
/**
12+
* @param non-empty-list<array<string, mixed>> $list
13+
*/
14+
public function testList1(array $list): void
15+
{
16+
assertType('non-empty-list<mixed>', array_column($list, 'value'));
17+
}
18+
}

0 commit comments

Comments
 (0)