1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Forbid template annotation on closures (#5499)

They don't work properly anyway.

Fixes vimeo/psalm#5472
This commit is contained in:
Bruce Weirdan 2021-03-29 22:10:04 +03:00 committed by GitHub
parent adc5368b97
commit 6bd7f5b867
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View File

@ -455,6 +455,18 @@ class FunctionLikeNodeScanner
}
}
if ($stmt instanceof PhpParser\Node\Expr\Closure
|| $stmt instanceof PhpParser\Node\Expr\ArrowFunction
) {
if ($docblock_info->templates !== []) {
$docblock_info->templates = [];
$storage->docblock_issues[] = new InvalidDocblock(
'Templated closures are not supported',
new CodeLocation($this->file_scanner, $stmt, null, true)
);
}
}
FunctionLikeDocblockScanner::addDocblockInfo(
$this->codebase,
$this->file_scanner,

View File

@ -926,6 +926,23 @@ class ClosureTest extends TestCase
false,
'7.4'
],
'forbidTemplateAnnotationOnClosure' => [
'<?php
/** @template T */
function (): void {};
',
'error_message' => 'InvalidDocblock',
],
'forbidTemplateAnnotationOnShortClosure' => [
'<?php
/** @template T */
fn(): bool => false;
',
'error_message' => 'InvalidDocblock',
[],
false,
'7.4'
],
];
}
}