-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inferring template types on arrays
Closes phpstan/phpstan#4209
- Loading branch information
1 parent
6d228a5
commit 19e3cde
Showing
7 changed files
with
156 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Bug4209Two; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Customer | ||
{ | ||
public function getName(): string { return 'customer'; } | ||
} | ||
|
||
/** | ||
* @template T | ||
*/ | ||
interface Link { | ||
/** | ||
* @return T | ||
*/ | ||
public function getItem(); | ||
} | ||
|
||
/** | ||
* @implements Link<Customer> | ||
*/ | ||
class CustomerLink implements Link | ||
{ | ||
/** | ||
* @var Customer | ||
*/ | ||
public $item; | ||
|
||
/** | ||
* @param Customer $item | ||
*/ | ||
public function __construct($item) { | ||
$this->item = $item; | ||
} | ||
|
||
/** | ||
* @return Customer | ||
*/ | ||
public function getItem() | ||
{ | ||
return $this->item; | ||
} | ||
} | ||
|
||
/** | ||
* @return CustomerLink[] | ||
*/ | ||
function get_links(): array { | ||
return [new CustomerLink(new Customer())]; | ||
} | ||
|
||
/** | ||
* @template T | ||
* @param Link<T>[] $links | ||
* @return T | ||
*/ | ||
function process_customers(array $links) { | ||
// no-op | ||
} | ||
|
||
class Runner { | ||
public function run(): void | ||
{ | ||
assertType('Bug4209Two\Customer', process_customers(get_links())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Bug4209; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
/** | ||
* @template T | ||
*/ | ||
class Link { | ||
/** | ||
* @var T | ||
*/ | ||
public $item; | ||
|
||
/** | ||
* @param T $item | ||
*/ | ||
public function __construct($item) { | ||
$this->item = $item; | ||
} | ||
} | ||
|
||
class Customer | ||
{ | ||
public function getName(): string { return 'customer'; } | ||
} | ||
|
||
/** | ||
* @return Link<Customer>[] | ||
*/ | ||
function get_links(): array { | ||
return [new Link(new Customer())]; | ||
} | ||
|
||
/** | ||
* @template T | ||
* @param Link<T>[] $links | ||
* @return T | ||
*/ | ||
function process_customers(array $links) { | ||
// no-op | ||
} | ||
|
||
class Runner { | ||
public function run(): void | ||
{ | ||
assertType('Bug4209\Customer', process_customers(get_links())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters