Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
use PHPStan\Type\ErrorType;
use PHPStan\Type\ExpressionTypeResolverExtensionRegistry;
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\IntegerRangeType;
Expand Down Expand Up @@ -2731,7 +2732,7 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
if ($dimType->isInteger()->yes() || $dimType->isString()->yes()) {
$exprVarType = $scope->getType($expr->var);
$isArray = $exprVarType->isArray();
if (!$exprVarType instanceof MixedType && !$isArray->no()) {
if (!$exprVarType instanceof MixedType && !$isArray->no() && !$exprVarType instanceof TemplateType) {
$tooManyHasOffsetValueTypes = false;

$varType = $exprVarType;
Expand Down
27 changes: 27 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-10172.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php declare(strict_types = 1);

namespace Bug10172;

use function PHPStan\Testing\assertType;

class HelloWorld
{
/**
* @template T of array{data: array<mixed>}
*
* @param T $a
*
* @return T
*/
public function foo(array $a): array
{
assertType('T of array{data: array<mixed>} (method Bug10172\HelloWorld::foo(), argument)', $a);

foreach ($a['data'] as $i) {
}

assertType('T of array{data: array<mixed>} (method Bug10172\HelloWorld::foo(), argument)', $a);

return $a;
}
}
Loading