Skip to content

Commit

Permalink
Revert "Improve for loop initial statement scope pollution"
Browse files Browse the repository at this point in the history
This reverts commit c55aa05.
  • Loading branch information
ondrejmirtes committed Nov 10, 2024
1 parent 381c137 commit f2dfd5d
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 356 deletions.
62 changes: 0 additions & 62 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4900,68 +4900,6 @@ public function processAlwaysIterableForeachScopeWithoutPollute(self $finalScope
);
}

public function processAlwaysIterableForScopeWithoutPollute(self $finalScope, self $initScope): self
{
$expressionTypes = $this->expressionTypes;
$initScopeExpressionTypes = $initScope->expressionTypes;
foreach ($finalScope->expressionTypes as $variableExprString => $variableTypeHolder) {
if (!isset($expressionTypes[$variableExprString])) {
if (isset($initScopeExpressionTypes[$variableExprString])) {
$expressionTypes[$variableExprString] = ExpressionTypeHolder::createMaybe($variableTypeHolder->getExpr(), $variableTypeHolder->getType());
continue;
}

$expressionTypes[$variableExprString] = $variableTypeHolder;
continue;
}

$expressionTypes[$variableExprString] = new ExpressionTypeHolder(
$variableTypeHolder->getExpr(),
$variableTypeHolder->getType(),
$variableTypeHolder->getCertainty()->and($expressionTypes[$variableExprString]->getCertainty()),
);
}

$nativeTypes = $this->nativeExpressionTypes;
$initScopeNativeExpressionTypes = $initScope->nativeExpressionTypes;
foreach ($finalScope->nativeExpressionTypes as $variableExprString => $variableTypeHolder) {
if (!isset($nativeTypes[$variableExprString])) {
if (isset($initScopeNativeExpressionTypes[$variableExprString])) {
$nativeTypes[$variableExprString] = ExpressionTypeHolder::createMaybe($variableTypeHolder->getExpr(), $variableTypeHolder->getType());
continue;
}

$nativeTypes[$variableExprString] = $variableTypeHolder;
continue;
}

$nativeTypes[$variableExprString] = new ExpressionTypeHolder(
$variableTypeHolder->getExpr(),
$variableTypeHolder->getType(),
$variableTypeHolder->getCertainty()->and($nativeTypes[$variableExprString]->getCertainty()),
);
}

return $this->scopeFactory->create(
$this->context,
$this->isDeclareStrictTypes(),
$this->getFunction(),
$this->getNamespace(),
$expressionTypes,
$nativeTypes,
$this->conditionalExpressions,
$this->inClosureBindScopeClasses,
$this->anonymousFunctionReflection,
$this->inFirstLevelStatement,
[],
[],
[],
$this->afterExtractCall,
$this->parentScope,
$this->nativeTypesPromoted,
);
}

public function generalizeWith(self $otherScope): self
{
$variableTypeHolders = $this->generalizeVariableTypeHolders(
Expand Down
2 changes: 1 addition & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ private function processStmtNode(
}
} else {
if (!$this->polluteScopeWithLoopInitialAssignments) {
$finalScope = $scope->processAlwaysIterableForScopeWithoutPollute($finalScope, $initScope);
$finalScope = $finalScope->mergeWith($scope);
}
}

Expand Down
36 changes: 0 additions & 36 deletions tests/PHPStan/Analyser/ForLoopNoScopePollutionTest.php

This file was deleted.

107 changes: 0 additions & 107 deletions tests/PHPStan/Analyser/data/for-loop-no-scope-pollution.php

This file was deleted.

2 changes: 0 additions & 2 deletions tests/PHPStan/Analyser/forLoopNoScopePollution.neon

This file was deleted.

107 changes: 0 additions & 107 deletions tests/PHPStan/Analyser/nsrt/for-loop.php

This file was deleted.

9 changes: 0 additions & 9 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,4 @@ public function testBug10228(): void
$this->analyse([__DIR__ . '/data/bug-10228.php'], []);
}

public function testBug9550(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-9550.php'], []);
}

}
32 changes: 0 additions & 32 deletions tests/PHPStan/Rules/Variables/data/bug-9550.php

This file was deleted.

0 comments on commit f2dfd5d

Please sign in to comment.