Skip to content

Commit dac3332

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents fbba482 + a12642a commit dac3332

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Type/Accessory/AccessoryNonEmptyStringType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function getConstantStrings(): array
7272

7373
public function accepts(Type $type, bool $strictTypes): AcceptsResult
7474
{
75+
if ($type->isNonEmptyString()->yes()) {
76+
return AcceptsResult::createYes();
77+
}
7578
if ($type instanceof CompoundType) {
7679
return $type->isAcceptedBy($this, $strictTypes);
7780
}

src/Type/IntersectionType.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,9 @@ public function isNumericString(): TrinaryLogic
669669

670670
public function isNonEmptyString(): TrinaryLogic
671671
{
672+
if ($this->isCallable()->yes() && $this->isString()->yes()) {
673+
return TrinaryLogic::createYes();
674+
}
672675
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isNonEmptyString());
673676
}
674677

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,12 @@ public function testBug12949(): void
16001600
$this->assertSame('Access to undefined constant object::0.', $errors[2]->getMessage());
16011601
}
16021602

1603+
public function testBug12979(): void
1604+
{
1605+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12979.php');
1606+
$this->assertNoErrors($errors);
1607+
}
1608+
16031609
/**
16041610
* @param string[]|null $allAnalysedFiles
16051611
* @return Error[]
Lines changed: 21 additions & 0 deletions
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)