Skip to content

Commit

Permalink
Merge branch refs/heads/1.12.x into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot authored Dec 11, 2024
2 parents 5711cdd + e9e419c commit 961150e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Type/Regex/RegexGroupParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,19 @@ private function getLiteralValue(TreeNode $node, ?array &$onlyLiterals, bool $ap
if (
$appendLiterals
&& $onlyLiterals !== null
&& (!in_array($value, ['.'], true) || $isEscaped || $inCharacterClass)
) {
if ($onlyLiterals === []) {
$onlyLiterals = [$value];
if (
in_array($value, ['.'], true)
&& !($isEscaped || $inCharacterClass)
) {
$onlyLiterals = null;
} else {
foreach ($onlyLiterals as &$literal) {
$literal .= $value;
if ($onlyLiterals === []) {
$onlyLiterals = [$value];
} else {
foreach ($onlyLiterals as &$literal) {
$literal .= $value;
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-12211.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php // lint >= 7.4

declare(strict_types = 1);

namespace Bug12211;

use function PHPStan\Testing\assertType;

const REGEX = '((m.x))';

function foo(string $text): void {
assert(preg_match(REGEX, $text, $match) === 1);
assertType('array{string, non-falsy-string}', $match);
}


0 comments on commit 961150e

Please sign in to comment.