From 66bbe5bb747da1e326bd302ba35e7da475988a3f Mon Sep 17 00:00:00 2001 From: Brown Date: Thu, 16 May 2019 13:52:58 -0400 Subject: [PATCH] Allow space in intersection type Ref #1645 --- src/Psalm/Internal/Analyzer/CommentAnalyzer.php | 14 +++++++++----- tests/AnnotationTest.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php index 851dfca02..af97ec9fa 100644 --- a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php @@ -991,13 +991,17 @@ class CommentAnalyzer continue; } - if ($next_char === '|') { - ++$i; - $type .= $next_char; - continue; + if ($next_char === '|' || $next_char === '&') { + $nexter_char = $i < $l - 2 ? $return_block[$i + 2] : null; + + if ($nexter_char === ' ') { + ++$i; + $type .= $next_char; + continue; + } } - if ($last_char === '|') { + if ($last_char === '|' || $last_char === '&') { continue; } diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 4390889f0..66dc1efd0 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -974,6 +974,21 @@ class AnnotationTest extends TestCase private $s = null; }', ], + 'intersectionWithSpace' => [ + 'foo(); + $a->bar(); + }' + ], ]; }