mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #3927 - prevent crash with bad type ref
This commit is contained in:
parent
a356a43a51
commit
ec2178d14a
@ -609,24 +609,39 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
}
|
||||
}
|
||||
|
||||
$classlike_storage->type_aliases = \array_map(
|
||||
$converted_aliases = \array_map(
|
||||
function (TypeAlias\InlineTypeAlias $t) {
|
||||
$union = TypeParser::parseTokens(
|
||||
$t->replacement_tokens,
|
||||
null,
|
||||
[],
|
||||
$this->type_aliases
|
||||
);
|
||||
try {
|
||||
$union = TypeParser::parseTokens(
|
||||
$t->replacement_tokens,
|
||||
null,
|
||||
[],
|
||||
$this->type_aliases
|
||||
);
|
||||
|
||||
$union->setFromDocblock();
|
||||
$union->setFromDocblock();
|
||||
|
||||
return new TypeAlias\ClassTypeAlias(
|
||||
\array_values($union->getAtomicTypes())
|
||||
);
|
||||
return new TypeAlias\ClassTypeAlias(
|
||||
\array_values($union->getAtomicTypes())
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
$this->classlike_type_aliases
|
||||
);
|
||||
|
||||
foreach ($converted_aliases as $key => $type) {
|
||||
if (!$type) {
|
||||
$classlike_storage->docblock_issues[] = new InvalidDocblock(
|
||||
'@psalm-type ' . $key . ' contains invalid references',
|
||||
new CodeLocation($this->file_scanner, $node, null, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$classlike_storage->type_aliases = \array_filter($converted_aliases);
|
||||
|
||||
$this->classlike_type_aliases = [];
|
||||
|
||||
if ($classlike_storage->has_visitor_issues) {
|
||||
|
@ -386,6 +386,17 @@ class TypeAnnotationTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'UndefinedDocblockClass',
|
||||
],
|
||||
'noCrashWithPriorReference' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-type _C=array{c:_CC}
|
||||
* @psalm-type _CC=float
|
||||
*/
|
||||
class A {
|
||||
|
||||
}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user