-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed inferring from nested class-string
- Loading branch information
1 parent
ec2ef2a
commit a7a46b1
Showing
4 changed files
with
78 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug4552; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
interface OptionPresenter {} | ||
|
||
/** | ||
* @template TPresenter of OptionPresenter | ||
*/ | ||
interface OptionDefinition { | ||
/** | ||
* @return TPresenter | ||
*/ | ||
public function presenter(); | ||
} | ||
|
||
class SimpleOptionPresenter implements OptionPresenter { | ||
public function test(): bool | ||
{ | ||
|
||
} | ||
} | ||
|
||
/** | ||
* @template-implements OptionDefinition<SimpleOptionPresenter> | ||
*/ | ||
class SimpleOptionDefinition implements OptionDefinition { | ||
public function presenter() | ||
{ | ||
return new SimpleOptionPresenter(); | ||
} | ||
} | ||
|
||
/** | ||
* @template T of OptionPresenter | ||
* | ||
* @param class-string<OptionDefinition<T>> $definition | ||
* | ||
* @return T | ||
*/ | ||
function present($definition) { | ||
return instantiate($definition)->presenter(); | ||
} | ||
|
||
|
||
/** | ||
* @template T of OptionDefinition | ||
* | ||
* @param class-string<T> $definition | ||
* | ||
* @return T | ||
*/ | ||
function instantiate($definition) { | ||
return new $definition; | ||
} | ||
|
||
function (): void { | ||
$p = present(SimpleOptionDefinition::class); | ||
assertType(SimpleOptionPresenter::class, $p); | ||
$p->test(); | ||
}; |