-
Notifications
You must be signed in to change notification settings - Fork 544
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 2 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 |
|---|---|---|
|
|
@@ -291,6 +291,25 @@ | |
| if ($specifiedTypes !== null) { | ||
| $result = $result->unionWith($specifiedTypes); | ||
| } | ||
| if ( | ||
| $context->true() | ||
| && $expr instanceof Node\Expr\BinaryOp\Smaller | ||
| && $argType->isList()->yes() | ||
| && IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($leftType)->yes() | ||
| ) { | ||
| $dimFetch = new ArrayDimFetch( | ||
| $expr->right->getArgs()[0]->value, | ||
| $expr->left, | ||
| ); | ||
| $result = $result->unionWith( | ||
| $this->create( | ||
| $dimFetch, | ||
| $argType->getIterableValueType(), | ||
| TypeSpecifierContext::createTrue(), | ||
| $scope, | ||
| ) | ||
| ); | ||
| } | ||
|
Comment on lines
295
to
314
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. is this PR trying to fix phpstan/phpstan#13773 ? if so, you should either adjust the logic added with #4403 or maybe even delete it in case you want to re-implement it in a different place
Contributor
Author
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. Thanks for pointing this out! I updated the description of this pr. I have not opened a issue for this pr. But i will also try and fix phpstan/phpstan#13773 later in a diffrent pr. Here i am trying to fix array access on lists if we explicitly guard the index. |
||
|
|
||
| if ( | ||
| $context->true() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes()) | ||
|
|
@@ -500,7 +519,7 @@ | |
| } | ||
|
|
||
| if (count($expr->getArgs()) > 0) { | ||
| $specifiedTypes = $this->specifyTypesFromConditionalReturnType($context, $expr, $parametersAcceptor, $scope); | ||
|
Check failure on line 522 in src/Analyser/TypeSpecifier.php
|
||
| if ($specifiedTypes !== null) { | ||
| return $specifiedTypes; | ||
| } | ||
|
|
@@ -510,7 +529,7 @@ | |
| if ($assertions->getAll() !== []) { | ||
| $parametersAcceptor ??= ParametersAcceptorSelector::selectFromArgs($scope, $expr->getArgs(), $functionReflection->getVariants(), $functionReflection->getNamedArgumentsVariants()); | ||
|
|
||
| $asserts = $assertions->mapTypes(static fn (Type $type) => TemplateTypeHelper::resolveTemplateTypes( | ||
|
Check failure on line 532 in src/Analyser/TypeSpecifier.php
|
||
| $type, | ||
| $parametersAcceptor->getResolvedTemplateTypeMap(), | ||
| $parametersAcceptor instanceof ExtendedParametersAcceptor ? $parametersAcceptor->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(), | ||
|
|
@@ -553,7 +572,7 @@ | |
| } | ||
|
|
||
| if (count($expr->getArgs()) > 0) { | ||
| $specifiedTypes = $this->specifyTypesFromConditionalReturnType($context, $expr, $parametersAcceptor, $scope); | ||
|
Check failure on line 575 in src/Analyser/TypeSpecifier.php
|
||
| if ($specifiedTypes !== null) { | ||
| return $specifiedTypes; | ||
| } | ||
|
|
@@ -563,7 +582,7 @@ | |
| if ($assertions->getAll() !== []) { | ||
| $parametersAcceptor ??= ParametersAcceptorSelector::selectFromArgs($scope, $expr->getArgs(), $methodReflection->getVariants(), $methodReflection->getNamedArgumentsVariants()); | ||
|
|
||
| $asserts = $assertions->mapTypes(static fn (Type $type) => TemplateTypeHelper::resolveTemplateTypes( | ||
|
Check failure on line 585 in src/Analyser/TypeSpecifier.php
|
||
| $type, | ||
| $parametersAcceptor->getResolvedTemplateTypeMap(), | ||
| $parametersAcceptor instanceof ExtendedParametersAcceptor ? $parametersAcceptor->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(), | ||
|
|
@@ -611,7 +630,7 @@ | |
| } | ||
|
|
||
| if (count($expr->getArgs()) > 0) { | ||
| $specifiedTypes = $this->specifyTypesFromConditionalReturnType($context, $expr, $parametersAcceptor, $scope); | ||
|
Check failure on line 633 in src/Analyser/TypeSpecifier.php
|
||
| if ($specifiedTypes !== null) { | ||
| return $specifiedTypes; | ||
| } | ||
|
|
@@ -621,7 +640,7 @@ | |
| if ($assertions->getAll() !== []) { | ||
| $parametersAcceptor ??= ParametersAcceptorSelector::selectFromArgs($scope, $expr->getArgs(), $staticMethodReflection->getVariants(), $staticMethodReflection->getNamedArgumentsVariants()); | ||
|
|
||
| $asserts = $assertions->mapTypes(static fn (Type $type) => TemplateTypeHelper::resolveTemplateTypes( | ||
|
Check failure on line 643 in src/Analyser/TypeSpecifier.php
|
||
| $type, | ||
| $parametersAcceptor->getResolvedTemplateTypeMap(), | ||
| $parametersAcceptor instanceof ExtendedParametersAcceptor ? $parametersAcceptor->getCallSiteVarianceMap() : TemplateTypeVarianceMap::createEmpty(), | ||
|
|
||
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.
usually we pass thru the $context, instead of creating a new one.