From 7335a05c2b71c546f51fd121027afcb5431e0d6b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 3 Sep 2024 20:36:52 +0200 Subject: [PATCH] ArrayShapeMatcher - Fix alternations containing a $-only case --- src/Type/Regex/RegexGroupParser.php | 2 +- tests/PHPStan/Analyser/nsrt/preg_match_shapes.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Type/Regex/RegexGroupParser.php b/src/Type/Regex/RegexGroupParser.php index 0cfbb26e2e..03bbcb6cce 100644 --- a/src/Type/Regex/RegexGroupParser.php +++ b/src/Type/Regex/RegexGroupParser.php @@ -460,7 +460,7 @@ private function walkGroupAst( $isNumeric = TrinaryLogic::createYes(); } - if (!$inOptionalQuantification) { + if (!$inOptionalQuantification && $literalValue !== '') { $isNonEmpty = TrinaryLogic::createYes(); } } diff --git a/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php b/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php index f4ed3b7ffe..694a7cc886 100644 --- a/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php +++ b/tests/PHPStan/Analyser/nsrt/preg_match_shapes.php @@ -746,3 +746,10 @@ function bug11490b (string $expression): void { } } +function bug11622 (string $expression): void { + $matches = []; + + if (preg_match('/^abc(def|$)/', $expression, $matches) === 1) { + assertType("array{string, string}", $matches); + } +}