Skip to content

Commit 06f7c33

Browse files
committed
simpler fix
1 parent 6f59842 commit 06f7c33

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/Type/CallableType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,20 @@ public function __construct(
8484
?TemplateTypeMap $resolvedTemplateTypeMap = null,
8585
private array $templateTags = [],
8686
?TrinaryLogic $isPure = null,
87+
?bool $isCommonCallable = null,
8788
)
8889
{
8990
$this->parameters = $parameters ?? [];
9091
$this->returnType = $returnType ?? new MixedType();
91-
$this->isCommonCallable = $parameters === null && $returnType === null;
9292
$this->templateTypeMap = $templateTypeMap ?? TemplateTypeMap::createEmpty();
9393
$this->resolvedTemplateTypeMap = $resolvedTemplateTypeMap ?? TemplateTypeMap::createEmpty();
9494
$this->isPure = $isPure ?? TrinaryLogic::createMaybe();
95+
96+
if ($isCommonCallable !== null) {
97+
$this->isCommonCallable = $isCommonCallable;
98+
} else {
99+
$this->isCommonCallable = $parameters === null && $returnType === null;
100+
}
95101
}
96102

97103
/**

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,13 @@ public function getArray(): Type
315315

316316
if ($this->degradeClosures) {
317317
$itemTypes = [];
318-
$returnTypes = [];
318+
$itemTypes[] = new CallableType(isCommonCallable: false);
319319
foreach ($this->valueTypes as $valueType) {
320320
if ($valueType instanceof ClosureType) {
321-
$returnTypes[] = $valueType->getReturnType();
322321
continue;
323322
}
324323
$itemTypes[] = $valueType;
325324
}
326-
$itemTypes[] = new CallableType(null, TypeCombinator::union(...$returnTypes));
327325
} else {
328326
$itemTypes = $this->valueTypes;
329327
}

tests/PHPStan/Analyser/nsrt/degrade-closures-return-types.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
assertType('array{Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): 1, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): true}', $arr);
2424

2525
$arr[] = static function () {};
26-
assertType('non-empty-list<callable(): (1|void|true)>&oversized-array', $arr);
26+
assertType('non-empty-list<callable(): mixed>&oversized-array', $arr);

tests/PHPStan/Analyser/nsrt/degrade-closures.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
assertType('array{Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void, Closure(): void}', $arr);
2424

2525
$arr[] = static function () {};
26-
assertType('non-empty-list<callable(): void>&oversized-array', $arr);
26+
assertType('non-empty-list<callable(): mixed>&oversized-array', $arr);

0 commit comments

Comments
 (0)