-
Notifications
You must be signed in to change notification settings - Fork 545
Fix non-existent offset when guarding #4539
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
base: 2.1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,7 +273,8 @@ public function specifyTypesInCondition( | |
| && in_array(strtolower((string) $expr->right->name), ['count', 'sizeof'], true) | ||
| && $leftType->isInteger()->yes() | ||
| ) { | ||
| $argType = $scope->getType($expr->right->getArgs()[0]->value); | ||
| $argExpr = $expr->right->getArgs()[0]->value; | ||
| $argType = $scope->getType($argExpr); | ||
|
|
||
| if ($leftType instanceof ConstantIntegerType) { | ||
| if ($orEqual) { | ||
|
|
@@ -291,6 +292,26 @@ public function specifyTypesInCondition( | |
| if ($specifiedTypes !== null) { | ||
| $result = $result->unionWith($specifiedTypes); | ||
| } | ||
| if ( | ||
| $context->true() | ||
| && $expr instanceof Node\Expr\BinaryOp\Smaller | ||
| && $argType->isList()->yes() | ||
| && $argExpr instanceof Expr\Variable | ||
| && IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($leftType)->yes() | ||
| ) { | ||
| $dimFetch = new ArrayDimFetch( | ||
| $argExpr, | ||
| $expr->left, | ||
| ); | ||
| $result = $result->unionWith( | ||
| $this->create( | ||
| $dimFetch, | ||
| $argType->getIterableValueType(), | ||
| TypeSpecifierContext::createTrue(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usually we pass thru the $context, instead of creating a new one. |
||
| $scope, | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| if ( | ||
| $context->true() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,7 @@ public function sayHello(array $c): void | |
| assertType('list<int>', $c); | ||
| if (count($c) > 0) { | ||
| $c = array_map(fn() => new stdClass(), $c); | ||
| assertType('non-empty-list<stdClass>', $c); | ||
| assertType('non-empty-list<stdClass>&hasOffsetValue(0, stdClass)', $c); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this type does not make sense, because |
||
| } else { | ||
| assertType('array{}', $c); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
instanceof Expr\Variableis usually a bug as most logic works for other expressions (e.g. a pure function call can also be remembered).most of the time this works just by dropping this line