mirror of
https://github.com/danog/psalm.git
synced 2024-12-03 10:07:52 +01:00
Fix #3927 - prevent crash with bad type ref
This commit is contained in:
parent
a356a43a51
commit
ec2178d14a
@ -609,8 +609,9 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$classlike_storage->type_aliases = \array_map(
|
$converted_aliases = \array_map(
|
||||||
function (TypeAlias\InlineTypeAlias $t) {
|
function (TypeAlias\InlineTypeAlias $t) {
|
||||||
|
try {
|
||||||
$union = TypeParser::parseTokens(
|
$union = TypeParser::parseTokens(
|
||||||
$t->replacement_tokens,
|
$t->replacement_tokens,
|
||||||
null,
|
null,
|
||||||
@ -623,10 +624,24 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
return new TypeAlias\ClassTypeAlias(
|
return new TypeAlias\ClassTypeAlias(
|
||||||
\array_values($union->getAtomicTypes())
|
\array_values($union->getAtomicTypes())
|
||||||
);
|
);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
$this->classlike_type_aliases
|
$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 = [];
|
$this->classlike_type_aliases = [];
|
||||||
|
|
||||||
if ($classlike_storage->has_visitor_issues) {
|
if ($classlike_storage->has_visitor_issues) {
|
||||||
|
@ -386,6 +386,17 @@ class TypeAnnotationTest extends TestCase
|
|||||||
}',
|
}',
|
||||||
'error_message' => 'UndefinedDocblockClass',
|
'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