Skip to content

Commit c16582a

Browse files
committed
fix callable strings
1 parent 3d34649 commit c16582a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Type/CallableType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use PHPStan\Reflection\Php\DummyParameter;
2525
use PHPStan\ShouldNotHappenException;
2626
use PHPStan\TrinaryLogic;
27+
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
2728
use PHPStan\Type\Generic\TemplateType;
2829
use PHPStan\Type\Generic\TemplateTypeHelper;
2930
use PHPStan\Type\Generic\TemplateTypeMap;
@@ -331,7 +332,12 @@ public function toArrayKey(): Type
331332

332333
public function toCoercedArgumentType(bool $strictTypes): Type
333334
{
334-
return TypeCombinator::union($this, new StringType(), new ArrayType(new MixedType(true), new MixedType(true)), new ObjectType(Closure::class));
335+
return TypeCombinator::union(
336+
$this,
337+
TypeCombinator::intersect(new StringType(), new AccessoryNonEmptyStringType()),
338+
new ArrayType(new MixedType(true), new MixedType(true)),
339+
new ObjectType(Closure::class),
340+
);
335341
}
336342

337343
public function isOffsetAccessLegal(): TrinaryLogic

tests/PHPStan/Analyser/nsrt/bug-12393b.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ class CallableString {
584584

585585
public function doFoo(callable $foo): void {
586586
$this->foo = $foo;
587-
assertType('string', $this->foo); // could be non-empty-string
587+
assertType('callable-string|non-empty-string', $this->foo);
588588
}
589589
}
590590

0 commit comments

Comments
 (0)