-
Notifications
You must be signed in to change notification settings - Fork 483
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
Fix negative offset false positive on constant string #3784
base: 1.12.x
Are you sure you want to change the base?
Conversation
The bug report is about an error, the regression test should be in RuleTestCase. |
if ($offsetType instanceof ConstantIntegerType) { | ||
if ($offsetType->getValue() < strlen($this->value)) { | ||
if ($strLenType->isSuperTypeOf($offsetType)->yes()) { | ||
return new self($this->value[$offsetType->getValue()]); |
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.
this change also fixes a php warning which could happen on too small negative offsets (covered by the tests)
89c7f69
to
f5c2054
Compare
@@ -366,7 +366,7 @@ public function isUppercaseString(): TrinaryLogic | |||
public function hasOffsetValueType(Type $offsetType): TrinaryLogic | |||
{ | |||
if ($offsetType->isInteger()->yes()) { | |||
$strLenType = IntegerRangeType::fromInterval(0, strlen($this->value) - 1); | |||
$strLenType = IntegerRangeType::fromInterval(-strlen($this->value), strlen($this->value) - 1); |
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.
You know you could ask for strlen() just once :)
closes phpstan/phpstan#12122