-
Notifications
You must be signed in to change notification settings - Fork 529
RegexArrayShapeMatcher - fix capturing item-array-shapes for preg_match_all #3307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
if (!$this->containsSetOrder($flags) && !$this->containsUnmatchedAsNull($flags, $matchesAll) && $captureGroup->isOptional()) { | ||
$groupValueType = $this->getValueType( | ||
TypeCombinator::union($captureGroup->getType(), new ConstantStringType('')), | ||
$flags, | ||
$matchesAll, | ||
); | ||
$groupValueType = TypeCombinator::removeNull($groupValueType); | ||
} else { | ||
$groupValueType = $this->getValueType($captureGroup->getType(), $flags, $matchesAll); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -474,6 +478,8 @@ private function getValueType(Type $baseType, int $flags, bool $matchesAll): Typ | |||
$offsetType = IntegerRangeType::fromInterval(0, null); | |||
if ($this->containsUnmatchedAsNull($flags, $matchesAll)) { | |||
$valueType = TypeCombinator::addNull($valueType); | |||
} | |||
if ($this->containsUnmatchedAsNull($flags, $matchesAll) || $matchesAll) { | |||
// unmatched groups return -1 as offset | |||
$offsetType = IntegerRangeType::fromInterval(-1, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preg_match_all
can yield -1
in capturing offset, even without PREG_UNMATCHED_AS_NULL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. the same is true for preg_match
- https://3v4l.org/Yra1j
This pull request has been marked as ready for review. |
phpstan-nette needs expectation adjustments |
Thank you! |
No description provided.