diff --git a/src/Type/Accessory/NonEmptyArrayType.php b/src/Type/Accessory/NonEmptyArrayType.php index 3015e948ce..2718af8a53 100644 --- a/src/Type/Accessory/NonEmptyArrayType.php +++ b/src/Type/Accessory/NonEmptyArrayType.php @@ -76,10 +76,6 @@ public function getConstantStrings(): array public function accepts(Type $type, bool $strictTypes): AcceptsResult { - if ($type instanceof CompoundType) { - return $type->isAcceptedBy($this, $strictTypes); - } - $isArray = $type->isArray(); $isIterableAtLeastOnce = $type->isIterableAtLeastOnce(); diff --git a/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php b/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php index 38d4ec65d8..3e02085923 100644 --- a/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ClosureReturnTypeRuleTest.php @@ -133,4 +133,9 @@ public function testBugFunctionMethodConstants(): void $this->analyse([__DIR__ . '/data/bug-anonymous-function-method-constant.php'], []); } + public function testBug13964(): void + { + $this->analyse([__DIR__ . '/data/bug-13964.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-13964.php b/tests/PHPStan/Rules/Functions/data/bug-13964.php new file mode 100644 index 0000000000..489a1622f8 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-13964.php @@ -0,0 +1,17 @@ +> $state */ +$state = (fn()=>[])(); + +$state = array_map(function (array $item): array { + if (array_key_exists('type', $item) && array_key_exists('data', $item)) { + return $item; + } + + return [ + 'type' => 'hello', + 'data' => [], + ]; +}, $state); diff --git a/tests/PHPStan/Type/IntersectionTypeTest.php b/tests/PHPStan/Type/IntersectionTypeTest.php index 7318ba9c65..e3ed23eb46 100644 --- a/tests/PHPStan/Type/IntersectionTypeTest.php +++ b/tests/PHPStan/Type/IntersectionTypeTest.php @@ -10,6 +10,8 @@ use PHPStan\Type\Accessory\AccessoryArrayListType; use PHPStan\Type\Accessory\AccessoryLowercaseStringType; use PHPStan\Type\Accessory\AccessoryUppercaseStringType; +use PHPStan\Type\Accessory\HasOffsetType; +use PHPStan\Type\Accessory\HasOffsetValueType; use PHPStan\Type\Accessory\HasPropertyType; use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\Accessory\OversizedArrayType; @@ -70,6 +72,30 @@ public static function dataAccepts(): Iterator new CallableType(), TrinaryLogic::createMaybe(), ]; + + yield [ + TypeCombinator::intersect( + new ArrayType(new MixedType(), new MixedType()), + new NonEmptyArrayType(), + ), + TypeCombinator::intersect( + new ArrayType(new MixedType(), new MixedType()), + new HasOffsetType(new ConstantStringType('some-key')), + ), + TrinaryLogic::createYes(), + ]; + + yield [ + TypeCombinator::intersect( + new ArrayType(new MixedType(), new MixedType()), + new NonEmptyArrayType(), + ), + TypeCombinator::intersect( + new ArrayType(new MixedType(), new MixedType()), + new HasOffsetValueType(new ConstantStringType('some-key'), new IntegerType()), + ), + TrinaryLogic::createYes(), + ]; } #[DataProvider('dataAccepts')]