Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Type/Php/ArrayColumnHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public function getReturnValueType(Type $arrayType, Type $columnType, Scope $sco

if ($returnValueType === null) {
$returnValueType = $this->getOffsetOrProperty($iterableValueType, $columnType, $scope, true);
$iterableAtLeastOnce = TrinaryLogic::createMaybe();

// if (TypeCombinator::contains($arrayType, new NonEmptyArrayType())) {
// $iterableAtLeastOnce = TrinaryLogic::createYes();
// } else {
// $iterableAtLeastOnce = TrinaryLogic::createMaybe();
// }

if ($returnValueType === null) {
throw new ShouldNotHappenException();
}
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ public function testBug3379(): void
$this->assertSame('Constant SOME_UNKNOWN_CONST not found.', $errors[0]->getMessage());
}

public function testArraysBug(): void
{
$errors = $this->runAnalyse(__DIR__ . '/nsrt/bug-array-column.php');
$this->assertNoErrors($errors);
}

public function testBug3798(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3798.php');
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/nsrt/array-column.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ public function testObjects2(array $array): void
assertType('non-empty-array<DOMElement>', array_column($array, null, 'foo'));
}

/**
* @param non-empty-list<array<string, mixed>> $list
*/
public function testList1(array $list): void
{
assertType('non-empty-list<mixed>', array_column($list, 'value'));
}
}

final class Foo
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-array-column.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php // lint < 8.2

namespace ArrayColumn;

use DOMElement;
use function PHPStan\Testing\assertType;


class ArrayColumnTest
{
/**
* @param non-empty-list<array<string, mixed>> $list
*/
public function testList1(array $list): void
{
assertType('non-empty-list<mixed>', array_column($list, 'value'));
}
}
Loading