Skip to content

Commit e9e419c

Browse files
staabmondrejmirtes
authored andcommitted
RegexArrayShapeMatcher: fix regex wildcard omitted from type
1 parent 4d3a9ab commit e9e419c

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/Type/Regex/RegexGroupParser.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,19 @@ private function getLiteralValue(TreeNode $node, ?array &$onlyLiterals, bool $ap
535535
if (
536536
$appendLiterals
537537
&& $onlyLiterals !== null
538-
&& (!in_array($value, ['.'], true) || $isEscaped || $inCharacterClass)
539538
) {
540-
if ($onlyLiterals === []) {
541-
$onlyLiterals = [$value];
539+
if (
540+
in_array($value, ['.'], true)
541+
&& !($isEscaped || $inCharacterClass)
542+
) {
543+
$onlyLiterals = null;
542544
} else {
543-
foreach ($onlyLiterals as &$literal) {
544-
$literal .= $value;
545+
if ($onlyLiterals === []) {
546+
$onlyLiterals = [$value];
547+
} else {
548+
foreach ($onlyLiterals as &$literal) {
549+
$literal .= $value;
550+
}
545551
}
546552
}
547553
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php // lint >= 7.4
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug12211;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
const REGEX = '((m.x))';
10+
11+
function foo(string $text): void {
12+
assert(preg_match(REGEX, $text, $match) === 1);
13+
assertType('array{string, non-falsy-string}', $match);
14+
}
15+
16+

0 commit comments

Comments
 (0)