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); + } +}