Skip to content
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

Support @template-contravariant tags #140

Merged
merged 1 commit into from Jun 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Parser/PhpDocParser.php
Expand Up @@ -178,6 +178,9 @@ public function parseTagValue(TokenIterator $tokens, string $tag): Ast\PhpDoc\Ph
case '@template-covariant':
case '@phpstan-template-covariant':
case '@psalm-template-covariant':
case '@template-contravariant':
case '@phpstan-template-contravariant':
case '@psalm-template-contravariant':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm doesn't currently support @template-contravariant tags either, so I'm unsure whether this should be included.

Support would be welcomed, so I'd rather keep this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's no harm in having @psalm-template-contravariant here :)

$tagValue = $this->parseTemplateTagValue($tokens);
break;

Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Expand Up @@ -3323,6 +3323,21 @@ public function provideTemplateTagsData(): Iterator
),
]),
];

yield [
'OK with contravariance',
'/** @template-contravariant T */',
new PhpDocNode([
new PhpDocTagNode(
'@template-contravariant',
new TemplateTagValueNode(
'T',
null,
''
)
),
]),
];
}

public function provideExtendsTagsData(): Iterator
Expand Down