mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Be more strict about what can be a template as type
This commit is contained in:
parent
652b6eb8f2
commit
899dd16e8f
@ -870,6 +870,19 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$template_type->isSingle()) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidDocblock(
|
||||
'Template type cannot be a union in docblock for '
|
||||
. implode('.', $this->fq_classlike_names),
|
||||
new CodeLocation($this->file_scanner, $node, null, true)
|
||||
)
|
||||
)) {
|
||||
$storage->has_docblock_issues = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$storage->template_types[$template_name] = [
|
||||
$template_type,
|
||||
$fq_classlike_name
|
||||
|
@ -2018,6 +2018,14 @@ class TemplateTest extends TestCase
|
||||
$templated_list->add(5, []);',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
'unionTemplateType' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T0 as int|string
|
||||
*/
|
||||
class Foo {}',
|
||||
'error_message' => 'InvalidDocblock'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user