mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Merge pull request #9338 from weirdan/forbid-first-class-callables-in-new
This commit is contained in:
commit
538b4c80ed
@ -29,6 +29,7 @@ use Psalm\Issue\InternalClass;
|
||||
use Psalm\Issue\InternalMethod;
|
||||
use Psalm\Issue\InvalidStringClass;
|
||||
use Psalm\Issue\MixedMethodCall;
|
||||
use Psalm\Issue\ParseError;
|
||||
use Psalm\Issue\TooManyArguments;
|
||||
use Psalm\Issue\UndefinedClass;
|
||||
use Psalm\Issue\UnsafeGenericInstantiation;
|
||||
@ -84,6 +85,14 @@ class NewAnalyzer extends CallAnalyzer
|
||||
|
||||
$from_static = false;
|
||||
|
||||
if ($stmt->isFirstClassCallable()) {
|
||||
IssueBuffer::maybeAdd(new ParseError(
|
||||
'First-class callables cannot be used in new',
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt),
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($stmt->class instanceof PhpParser\Node\Name) {
|
||||
if (!in_array(strtolower($stmt->class->parts[0]), ['self', 'static', 'parent'], true)) {
|
||||
$aliases = $statements_analyzer->getAliases();
|
||||
|
@ -1419,6 +1419,15 @@ class ClosureTest extends TestCase
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '7.4',
|
||||
],
|
||||
'FirstClassCallable:WithNew' => [
|
||||
'code' => <<<'PHP'
|
||||
<?php
|
||||
new stdClass(...);
|
||||
PHP,
|
||||
'error_message' => 'ParseError',
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.1',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user