Skip to content

Fix callable-string must be non-empty-string #3983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.12.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Type/Accessory/AccessoryNonEmptyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic

public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
{
if ($type->isNonEmptyString()->yes()) {
return AcceptsResult::createYes();
}
if ($type instanceof CompoundType) {
return $type->isAcceptedWithReasonBy($this, $strictTypes);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ public function isNumericString(): TrinaryLogic

public function isNonEmptyString(): TrinaryLogic
{
if ($this->isCallable()->yes() && $this->isString()->yes()) {
return TrinaryLogic::createYes();
}
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isNonEmptyString());
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,12 @@ public function testBug11913(): void
$this->assertNoErrors($errors);
}

public function testBug12979(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12979.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
21 changes: 21 additions & 0 deletions tests/PHPStan/Analyser/data/bug-12979.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types = 1);

namespace Bug12979;

abstract class X
{
/**
* @return callable-string
*/
abstract public function callableString(): string;

/**
* @param non-empty-string $nonEmptyString
*/
abstract public function acceptNonEmptyString(string $nonEmptyString): void;

public function test(): void
{
$this->acceptNonEmptyString($this->callableString());
}
}
Loading