diff --git a/src/Type/Php/ArrayColumnHelper.php b/src/Type/Php/ArrayColumnHelper.php index 22e7eb69d0..b29b9ff193 100644 --- a/src/Type/Php/ArrayColumnHelper.php +++ b/src/Type/Php/ArrayColumnHelper.php @@ -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(); } diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 9124da8ce5..7baf6c6bc2 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -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'); diff --git a/tests/PHPStan/Analyser/nsrt/array-column.php b/tests/PHPStan/Analyser/nsrt/array-column.php index 4f830b96d9..4a3619226b 100644 --- a/tests/PHPStan/Analyser/nsrt/array-column.php +++ b/tests/PHPStan/Analyser/nsrt/array-column.php @@ -239,6 +239,13 @@ public function testObjects2(array $array): void assertType('non-empty-array', array_column($array, null, 'foo')); } + /** + * @param non-empty-list> $list + */ + public function testList1(array $list): void + { + assertType('non-empty-list', array_column($list, 'value')); + } } final class Foo diff --git a/tests/PHPStan/Analyser/nsrt/bug-array-column.php b/tests/PHPStan/Analyser/nsrt/bug-array-column.php new file mode 100644 index 0000000000..bf7778d304 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-array-column.php @@ -0,0 +1,18 @@ +> $list + */ + public function testList1(array $list): void + { + assertType('non-empty-list', array_column($list, 'value')); + } +}