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
7 changes: 6 additions & 1 deletion src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,12 @@ public function inferTemplateTypesOn(Type $templateType): TemplateTypeMap
$types = TemplateTypeMap::createEmpty();

foreach ($this->types as $type) {
$types = $types->intersect($templateType->inferTemplateTypes($type));
$inferred = $templateType->inferTemplateTypes($type);
if ($inferred->isEmpty() && $templateType instanceof TemplateType) {
$inferred = new TemplateTypeMap([$templateType->getName() => $type]);
}

$types = $types->intersect($inferred);
}

return $types;
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5129.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4970.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5322.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5336.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/splfixedarray-iterator-types.php');

if (PHP_VERSION_ID >= 70400 || self::$useStaticReflectionProvider) {
Expand Down
53 changes: 53 additions & 0 deletions tests/PHPStan/Analyser/data/bug-5336.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Bug5336;

use function PHPStan\Testing\assertType;

interface Stub
{
}

interface ProxyQueryInterface
{
}

/**
* @phpstan-template T of ProxyQueryInterface
*/
class Pager
{
/**
* @var T
*/
private $query;

/**
* @phpstan-param T $query
*/
public function __construct(ProxyQueryInterface $query) {
$this->query = $query;
}
}

abstract class Test
{
/**
* @var Pager<ProxyQueryInterface&Stub>
*/
private $pager;

/**
* @template T of object
* @param class-string<T> $originalClassName
* @return T&Stub
*/
abstract public function createStub(string $originalClassName): Stub;

public function sayHello(): void
{
$query = $this->createStub(ProxyQueryInterface::class);
$this->pager = new Pager($query);
assertType('Bug5336\Pager<Bug5336\ProxyQueryInterface&Bug5336\Stub>', $this->pager);
}
}