Skip to content

Commit

Permalink
Fixed wrong closure typehint
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 18, 2020
1 parent da9f6da commit 50aff6d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPStan\Analyser\OutOfClassScope;
use PHPStan\Reflection\ClassMemberAccessAnswerer;
use PHPStan\Reflection\Native\NativeParameterReflection;
use PHPStan\Reflection\ParameterReflection;
use PHPStan\Reflection\ParametersAcceptor;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Generic\TemplateTypeMap;
Expand Down Expand Up @@ -268,7 +269,7 @@ public function traverse(callable $cb): Type
return $this;
}

$parameters = array_map(static function (NativeParameterReflection $param) use ($cb): NativeParameterReflection {
$parameters = array_map(static function (ParameterReflection $param) use ($cb): NativeParameterReflection {
$defaultValue = $param->getDefaultValue();
return new NativeParameterReflection(
$param->getName(),
Expand Down
2 changes: 1 addition & 1 deletion src/Type/ClosureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private function inferTemplateTypesOnParametersAcceptor(Type $receivedType, Para
public function traverse(callable $cb): Type
{
return new self(
array_map(static function (NativeParameterReflection $param) use ($cb): NativeParameterReflection {
array_map(static function (ParameterReflection $param) use ($cb): NativeParameterReflection {
$defaultValue = $param->getDefaultValue();
return new NativeParameterReflection(
$param->getName(),
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 @@ -285,6 +285,12 @@ public function testBug3909(): void
$this->assertCount(0, $errors);
}

public function testBug4097(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-4097.php');
$this->assertCount(0, $errors);
}

/**
* @param string $file
* @return \PHPStan\Analyser\Error[]
Expand Down
33 changes: 33 additions & 0 deletions tests/PHPStan/Analyser/data/bug-4097.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Bug4097;

class Snapshot {}
class Fu {}
class Bar {}

/**
* @template T
*/
class SnapshotRepository
{
/**
* @return \Traversable<Snapshot>
*/
public function findAllSnapshots(): \Traversable
{
yield from \array_map(
\Closure::fromCallable([$this, 'buildSnapshot']),
[]
);
}

/**
* @param Fu|Bar $entity
* @phpstan-param T $entity
*/
public function buildSnapshot($entity): Snapshot
{
return new Snapshot();
}
}

0 comments on commit 50aff6d

Please sign in to comment.