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:
parent
adc5368b97
commit
6bd7f5b867
@ -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,
|
||||
|
@ -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'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user