mirror of
https://github.com/danog/psalm.git
synced 2024-12-11 16:59:45 +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) {
|
function (TypeAlias\InlineTypeAlias $t) {
|
||||||
$union = TypeParser::parseTokens(
|
try {
|
||||||
$t->replacement_tokens,
|
$union = TypeParser::parseTokens(
|
||||||
null,
|
$t->replacement_tokens,
|
||||||
[],
|
null,
|
||||||
$this->type_aliases
|
[],
|
||||||
);
|
$this->type_aliases
|
||||||
|
);
|
||||||
|
|
||||||
$union->setFromDocblock();
|
$union->setFromDocblock();
|
||||||
|
|
||||||
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