-
Notifications
You must be signed in to change notification settings - Fork 572
Fix phpstan/phpstan#11314: Template of imported type breaks imported type #5360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VincentLanglet
merged 4 commits into
phpstan:2.1.x
from
phpstan-bot:create-pull-request/patch-xt25se8
Apr 26, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
77d9a41
Fix phpstan/phpstan#11314: Template of imported type breaks imported …
github-actions[bot] 5d34b4b
Add regression tests for phpstan/phpstan#7152 and phpstan/phpstan#13332
phpstan-bot 98071b0
Add regression tests for phpstan/phpstan#7152 and phpstan/phpstan#13332
phpstan-bot 00599a8
Remove duplicate test fixtures, reference nsrt files from rule tests
phpstan-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,51 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug11314; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| /** | ||
| * @phpstan-type Breed 'Siamese'|'British Shorthair'|'Maine Coon' | ||
| */ | ||
| class Cat | ||
| { | ||
| /** | ||
| * @var Breed | ||
| */ | ||
| public string $breed; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-import-type Breed from Cat | ||
| * | ||
| * @template T of Breed | ||
| */ | ||
| class Cat2 | ||
| { | ||
| /** | ||
| * @var Breed | ||
| */ | ||
| public string $breed; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-import-type Breed from Cat | ||
| */ | ||
| class Cat3 | ||
| { | ||
| /** | ||
| * @var Breed | ||
| */ | ||
| public string $breed; | ||
| } | ||
|
|
||
| function () { | ||
| $cat = new Cat(); | ||
| assertType("'British Shorthair'|'Maine Coon'|'Siamese'", $cat->breed); | ||
|
|
||
| $cat2 = new Cat2(); | ||
| assertType("'British Shorthair'|'Maine Coon'|'Siamese'", $cat2->breed); | ||
|
|
||
| $cat3 = new Cat3(); | ||
| assertType("'British Shorthair'|'Maine Coon'|'Siamese'", $cat3->breed); | ||
| }; | ||
This file contains hidden or 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,65 @@ | ||
| <?php // lint >= 8.1 | ||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Bug13332; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| enum TestEnum { | ||
| case A; | ||
| case B; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-type KeyType string|int|\UnitEnum|object | ||
| * | ||
| * @template K of KeyType | ||
| */ | ||
| class TestError | ||
| { | ||
| /** @param K $key */ | ||
| public function __construct(private readonly mixed $key) | ||
| { | ||
| } | ||
|
|
||
| /** @return self<TestEnum> */ | ||
| public static function makeEnum(): self | ||
| { | ||
| return new self(TestEnum::A); | ||
| } | ||
|
|
||
| /** @return self<string> */ | ||
| public static function makeString(): self | ||
| { | ||
| return new self('foo'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @template K of string|int|\UnitEnum|object | ||
| */ | ||
| class TestOk | ||
| { | ||
| /** @param K $key */ | ||
| public function __construct(private readonly mixed $key) | ||
| { | ||
| } | ||
|
|
||
| /** @return self<TestEnum> */ | ||
| public static function makeEnum(): self | ||
| { | ||
| return new self(TestEnum::A); | ||
| } | ||
| } | ||
|
|
||
| function () { | ||
| $error = TestError::makeEnum(); | ||
| assertType('Bug13332\TestError<Bug13332\TestEnum>', $error); | ||
|
|
||
| $errorStr = TestError::makeString(); | ||
| assertType('Bug13332\TestError<string>', $errorStr); | ||
|
|
||
| $ok = TestOk::makeEnum(); | ||
| assertType('Bug13332\TestOk<Bug13332\TestEnum>', $ok); | ||
| }; |
This file contains hidden or 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,41 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace Bug7152; | ||
|
|
||
| use function PHPStan\Testing\assertType; | ||
|
|
||
| /** | ||
| * @template T of array<mixed> | ||
| */ | ||
| class Root | ||
| { | ||
| /** @var T */ | ||
| public array $value; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-type Foo array<int> | ||
| * @template T of Foo | ||
| * @extends Root<T> | ||
| */ | ||
| class Middle extends Root | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @template T of array<int> | ||
| * @extends Root<T> | ||
| */ | ||
| class Middle2 extends Root | ||
| { | ||
| } | ||
|
|
||
| function () { | ||
| /** @var Middle<array<int>> $m */ | ||
| $m = new Middle(); | ||
| assertType('array<int>', $m->value); | ||
|
|
||
| /** @var Middle2<array<int>> $m2 */ | ||
| $m2 = new Middle2(); | ||
| assertType('array<int>', $m2->value); | ||
| }; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.