Skip to content

Commit fc75deb

Browse files
Seldaekondrejmirtes
authored andcommitted
Fix bug parsing negative classes containing only digits ([^0-9])
1 parent dbb9665 commit fc75deb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Type/Php/RegexArrayShapeMatcher.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,13 @@ private function walkGroupAst(TreeNode $ast, TrinaryLogic &$isNonEmpty, TrinaryL
625625
}
626626
}
627627

628+
// [^0-9] should not parse as numeric-string, and [^list-everything-but-numbers] is technically
629+
// doable but really silly compared to just \d so we can safely assume the string is not numeric
630+
// for negative classes
631+
if ($ast->getId() === '#negativeclass') {
632+
$isNumeric = TrinaryLogic::createNo();
633+
}
634+
628635
foreach ($children as $child) {
629636
$this->walkGroupAst(
630637
$child,

tests/PHPStan/Analyser/nsrt/preg_match_shapes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,7 @@ function bug11323(string $s): void {
515515
if (preg_match('{(x?([1-4])\d)}', $s, $matches)) {
516516
assertType('array{string, non-empty-string, numeric-string}', $matches);
517517
}
518+
if (preg_match('{([^1-4])}', $s, $matches)) {
519+
assertType('array{string, non-empty-string}', $matches);
520+
}
518521
}

0 commit comments

Comments
 (0)