Skip to content
Merged
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
19 changes: 19 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3608,6 +3608,25 @@ public function testBug9141(): void
$this->analyse([__DIR__ . '/data/bug-9141.php'], []);
}

public function testBug3589(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->checkExplicitMixed = true;

$this->analyse([__DIR__ . '/data/bug-3589.php'], [
[
'Parameter #1 $fooId of method Bug3589\FooRepository::load() expects Bug3589\Id<Bug3589\Foo>, Bug3589\Id<Bug3589\Bar> given.',
35,
],
[
'Parameter #1 $fooId of method Bug3589\FooRepository::load() expects Bug3589\Id<Bug3589\Foo>, Bug3589\Id<mixed> given.',
41,
],
]);
}

public function testBug3396(): void
{
$this->checkThisOnly = false;
Expand Down
41 changes: 41 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3589.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types = 1);

namespace Bug3589;

class Foo{}
class Bar{}

/**
* @template Tpl
*/
class Id{}

class FooRepository
{
/**
* @param Id<Foo> $fooId
*/
public function load(Id $fooId): Foo
{
// ...
return new Foo;
}
}

$fooRepository = new FooRepository;

// Expected behavior: no error
/** @var Id<Foo> */
$fooId = new Id;
$fooRepository->load($fooId);

// Expected behavior: error on line 33
/** @var Id<Bar> */
$barId = new Id;
$fooRepository->load($barId);

// Expected behavior: errors
// - line 38 - Template Tpl is not specified
// - line 39 - Parameter #1 fooId of method FooRepository::load() expects Id<Foo>, nonspecified Id given.
$unknownId = new Id;
$fooRepository->load($unknownId);
Loading