Skip to content
Closed
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
1 change: 1 addition & 0 deletions .claude/worktrees/agent-a624340d
Submodule agent-a624340d added at 13a2f0
1 change: 1 addition & 0 deletions .claude/worktrees/agent-af2804bc
Submodule agent-af2804bc added at 173405
23 changes: 15 additions & 8 deletions src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
use PHPStan\Type\IterableType;
use PHPStan\Type\KeyOfType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NeverType;
use PHPStan\Type\NewObjectType;
use PHPStan\Type\NonAcceptingNeverType;
use PHPStan\Type\NonexistentParentClassType;
Expand Down Expand Up @@ -935,17 +936,23 @@ static function (string $variance): TemplateTypeVariance {

try {
if (count($genericTypes) === 1) { // Foo<ValueType>
return TypeCombinator::intersect(
$mainType,
new IterableType(new MixedType(true), $genericTypes[0]),
);
$iterableType = new IterableType(new MixedType(true), $genericTypes[0]);
$result = TypeCombinator::intersect($mainType, $iterableType);
if (!$result instanceof NeverType) {
return $result;
}

return new IntersectionType([$mainType, $iterableType]);
}

if (count($genericTypes) === 2) { // Foo<KeyType, ValueType>
return TypeCombinator::intersect(
$mainType,
new IterableType($genericTypes[0], $genericTypes[1]),
);
$iterableType = new IterableType($genericTypes[0], $genericTypes[1]);
$result = TypeCombinator::intersect($mainType, $iterableType);
if (!$result instanceof NeverType) {
return $result;
}

return new IntersectionType([$mainType, $iterableType]);
}
} finally {
if ($mainTypeClassName !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public function testBug6348(): void
$this->analyse([__DIR__ . '/data/bug-6348.php'], []);
}

public function testBug14206(): void
{
$this->analyse([__DIR__ . '/data/bug-14206.php'], []);
}

public function testBug9055(): void
{
$this->analyse([__DIR__ . '/data/bug-9055.php'], [
Expand Down
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/bug-14206.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);

namespace Bug14206;

use PDO;
use PDOStatement;

class Test
{
public function test(PDO $db): void
{
/** @var PDOStatement<int,string> */
$statement = $db->prepare('SELECT foo FROM bar');
$statement->setFetchMode(PDO::FETCH_COLUMN, 0);
$statement->execute();
}
}
Loading