Skip to content

Commit b5af16b

Browse files
committed
Fix callable-string must be non-empty-string
1 parent b7137d1 commit b5af16b

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Type/Accessory/AccessoryNonEmptyStringType.php

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic
7676

7777
public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
7878
{
79+
if ($type->isNonEmptyString()->yes()) {
80+
return AcceptsResult::createYes();
81+
}
7982
if ($type instanceof CompoundType) {
8083
return $type->isAcceptedWithReasonBy($this, $strictTypes);
8184
}

src/Type/IntersectionType.php

+3
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ public function isNumericString(): TrinaryLogic
645645

646646
public function isNonEmptyString(): TrinaryLogic
647647
{
648+
if ($this->isCallable()->yes() && $this->isString()->yes()) {
649+
return TrinaryLogic::createYes();
650+
}
648651
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isNonEmptyString());
649652
}
650653

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,12 @@ public function testBug11913(): void
14811481
$this->assertNoErrors($errors);
14821482
}
14831483

1484+
public function testBug12979(): void
1485+
{
1486+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12979.php');
1487+
$this->assertNoErrors($errors);
1488+
}
1489+
14841490
/**
14851491
* @param string[]|null $allAnalysedFiles
14861492
* @return Error[]
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12979;
4+
5+
abstract class X
6+
{
7+
/**
8+
* @return callable-string
9+
*/
10+
abstract public function callableString(): string;
11+
12+
/**
13+
* @param non-empty-string $nonEmptyString
14+
*/
15+
abstract public function acceptNonEmptyString(string $nonEmptyString): void;
16+
17+
public function test(): void
18+
{
19+
$this->acceptNonEmptyString($this->callableString());
20+
}
21+
}

0 commit comments

Comments
 (0)