File tree 4 files changed +54
-2
lines changed
4 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,17 @@ final class DocComment
40
40
/**
41
41
* Parse a docblock comment into its parts.
42
42
*/
43
- public static function parsePreservingLength (Doc $ docblock ): ParsedDocblock
43
+ public static function parsePreservingLength (Doc $ docblock, bool $ no_psalm_error = false ): ParsedDocblock
44
44
{
45
45
$ parsed_docblock = DocblockParser::parse (
46
46
$ docblock ->getText (),
47
47
$ docblock ->getStartFilePos (),
48
48
);
49
49
50
+ if ($ no_psalm_error ) {
51
+ return $ parsed_docblock ;
52
+ }
53
+
50
54
foreach ($ parsed_docblock ->tags as $ special_key => $ _ ) {
51
55
if (strpos ($ special_key , 'psalm- ' ) === 0 ) {
52
56
$ special_key = substr ($ special_key , 6 );
Original file line number Diff line number Diff line change @@ -802,6 +802,14 @@ private function parseStatementDocblock(
802
802
$ this ->parsed_docblock = null ;
803
803
}
804
804
805
+ if ($ this ->parsed_docblock === null ) {
806
+ try {
807
+ $ this ->parsed_docblock = DocComment::parsePreservingLength ($ docblock , true );
808
+ } catch (DocblockParseException $ e ) {
809
+ // already reported above
810
+ }
811
+ }
812
+
805
813
$ comments = $ this ->parsed_docblock ;
806
814
807
815
if (isset ($ comments ->tags ['psalm-scope-this ' ])) {
Original file line number Diff line number Diff line change @@ -53,7 +53,8 @@ public static function parse(
53
53
CodeLocation $ code_location ,
54
54
string $ cased_function_id
55
55
): FunctionDocblockComment {
56
- $ parsed_docblock = DocComment::parsePreservingLength ($ comment );
56
+ // invalid @psalm annotations are already reported by the StatementsAnalyzer
57
+ $ parsed_docblock = DocComment::parsePreservingLength ($ comment , true );
57
58
58
59
$ comment_text = $ comment ->getText ();
59
60
Original file line number Diff line number Diff line change @@ -535,6 +535,45 @@ public function ret(): array { return []; }
535
535
'$_=== ' => 'list<array{href: string, lang: string}> ' ,
536
536
],
537
537
],
538
+ 'invalidPsalmForMethodShouldNotBreakDocblock ' => [
539
+ 'code ' => '<?php
540
+ class A {
541
+ /**
542
+ * @psalm-impure
543
+ * @param string $arg
544
+ * @return non-falsy-string
545
+ */
546
+ public function foo($arg) {
547
+ return $arg . "bar";
548
+ }
549
+ }
550
+
551
+ $a = new A();
552
+ $_ = $a->foo("hello");
553
+ ' ,
554
+ 'assertions ' => [
555
+ '$_=== ' => 'non-falsy-string ' ,
556
+ ],
557
+ 'ignored_issues ' => ['InvalidDocblock ' ],
558
+ ],
559
+ 'invalidPsalmForFunctionShouldNotBreakDocblock ' => [
560
+ 'code ' => '<?php
561
+ /**
562
+ * @psalm-impure
563
+ * @param string $arg
564
+ * @return non-falsy-string
565
+ */
566
+ function foo($arg) {
567
+ return $arg . "bar";
568
+ }
569
+
570
+ $_ = foo("hello");
571
+ ' ,
572
+ 'assertions ' => [
573
+ '$_=== ' => 'non-falsy-string ' ,
574
+ ],
575
+ 'ignored_issues ' => ['InvalidDocblock ' ],
576
+ ],
538
577
'builtInClassInAShape ' => [
539
578
'code ' => '<?php
540
579
/**
You can’t perform that action at this time.
0 commit comments