Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Aug 8, 2024

No description provided.

Comment on lines +397 to +405
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);
Copy link
Contributor Author

@staabm staabm Aug 8, 2024

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);
Copy link
Contributor Author

@staabm staabm Aug 8, 2024

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

https://3v4l.org/qU6Fa

Copy link
Contributor Author

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

@staabm staabm marked this pull request as ready for review August 8, 2024 18:42
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm
Copy link
Contributor Author

staabm commented Aug 8, 2024

phpstan-nette needs expectation adjustments

@ondrejmirtes ondrejmirtes merged commit 427a319 into phpstan:1.11.x Aug 8, 2024
446 of 463 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the 11479b branch August 8, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants