Skip to content

Commit 4a2cf93

Browse files
committed
Don't crash on invalid templates
Fixes vimeo#9596
1 parent c511185 commit 4a2cf93

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,11 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool
434434
try {
435435
$type_string = CommentAnalyzer::splitDocLine($type_string)[0];
436436
} catch (DocblockParseException $e) {
437-
throw new DocblockParseException(
438-
$type_string . ' is not a valid type: ' . $e->getMessage(),
437+
$storage->docblock_issues[] = new InvalidDocblock(
438+
$e->getMessage() . ' in docblock for ' . $fq_classlike_name,
439+
$name_location ?? $class_location,
439440
);
441+
continue;
440442
}
441443
$type_string = CommentAnalyzer::sanitizeDocblockType($type_string);
442444
try {

tests/Template/ClassTemplateTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -5025,6 +5025,16 @@ function getMixedCollection(MyCollection $c): MyCollection {
50255025
}',
50265026
'error_message' => 'InvalidReturnStatement',
50275027
],
5028+
'noCrashOnBrokenTemplate' => [
5029+
'code' => <<<'PHP'
5030+
<?php
5031+
/**
5032+
* @template TValidationRule of callable>|string
5033+
*/
5034+
class C {}
5035+
PHP,
5036+
'error_message' => 'InvalidDocblock',
5037+
],
50285038
];
50295039
}
50305040
}

0 commit comments

Comments
 (0)