Skip to content

Commit f2dfd5d

Browse files
committed
Revert "Improve for loop initial statement scope pollution"
This reverts commit c55aa05.
1 parent 381c137 commit f2dfd5d

8 files changed

+1
-356
lines changed

src/Analyser/MutatingScope.php

-62
Original file line numberDiff line numberDiff line change
@@ -4900,68 +4900,6 @@ public function processAlwaysIterableForeachScopeWithoutPollute(self $finalScope
49004900
);
49014901
}
49024902

4903-
public function processAlwaysIterableForScopeWithoutPollute(self $finalScope, self $initScope): self
4904-
{
4905-
$expressionTypes = $this->expressionTypes;
4906-
$initScopeExpressionTypes = $initScope->expressionTypes;
4907-
foreach ($finalScope->expressionTypes as $variableExprString => $variableTypeHolder) {
4908-
if (!isset($expressionTypes[$variableExprString])) {
4909-
if (isset($initScopeExpressionTypes[$variableExprString])) {
4910-
$expressionTypes[$variableExprString] = ExpressionTypeHolder::createMaybe($variableTypeHolder->getExpr(), $variableTypeHolder->getType());
4911-
continue;
4912-
}
4913-
4914-
$expressionTypes[$variableExprString] = $variableTypeHolder;
4915-
continue;
4916-
}
4917-
4918-
$expressionTypes[$variableExprString] = new ExpressionTypeHolder(
4919-
$variableTypeHolder->getExpr(),
4920-
$variableTypeHolder->getType(),
4921-
$variableTypeHolder->getCertainty()->and($expressionTypes[$variableExprString]->getCertainty()),
4922-
);
4923-
}
4924-
4925-
$nativeTypes = $this->nativeExpressionTypes;
4926-
$initScopeNativeExpressionTypes = $initScope->nativeExpressionTypes;
4927-
foreach ($finalScope->nativeExpressionTypes as $variableExprString => $variableTypeHolder) {
4928-
if (!isset($nativeTypes[$variableExprString])) {
4929-
if (isset($initScopeNativeExpressionTypes[$variableExprString])) {
4930-
$nativeTypes[$variableExprString] = ExpressionTypeHolder::createMaybe($variableTypeHolder->getExpr(), $variableTypeHolder->getType());
4931-
continue;
4932-
}
4933-
4934-
$nativeTypes[$variableExprString] = $variableTypeHolder;
4935-
continue;
4936-
}
4937-
4938-
$nativeTypes[$variableExprString] = new ExpressionTypeHolder(
4939-
$variableTypeHolder->getExpr(),
4940-
$variableTypeHolder->getType(),
4941-
$variableTypeHolder->getCertainty()->and($nativeTypes[$variableExprString]->getCertainty()),
4942-
);
4943-
}
4944-
4945-
return $this->scopeFactory->create(
4946-
$this->context,
4947-
$this->isDeclareStrictTypes(),
4948-
$this->getFunction(),
4949-
$this->getNamespace(),
4950-
$expressionTypes,
4951-
$nativeTypes,
4952-
$this->conditionalExpressions,
4953-
$this->inClosureBindScopeClasses,
4954-
$this->anonymousFunctionReflection,
4955-
$this->inFirstLevelStatement,
4956-
[],
4957-
[],
4958-
[],
4959-
$this->afterExtractCall,
4960-
$this->parentScope,
4961-
$this->nativeTypesPromoted,
4962-
);
4963-
}
4964-
49654903
public function generalizeWith(self $otherScope): self
49664904
{
49674905
$variableTypeHolders = $this->generalizeVariableTypeHolders(

src/Analyser/NodeScopeResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ private function processStmtNode(
14101410
}
14111411
} else {
14121412
if (!$this->polluteScopeWithLoopInitialAssignments) {
1413-
$finalScope = $scope->processAlwaysIterableForScopeWithoutPollute($finalScope, $initScope);
1413+
$finalScope = $finalScope->mergeWith($scope);
14141414
}
14151415
}
14161416

tests/PHPStan/Analyser/ForLoopNoScopePollutionTest.php

-36
This file was deleted.

tests/PHPStan/Analyser/data/for-loop-no-scope-pollution.php

-107
This file was deleted.

tests/PHPStan/Analyser/forLoopNoScopePollution.neon

-2
This file was deleted.

tests/PHPStan/Analyser/nsrt/for-loop.php

-107
This file was deleted.

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

-9
Original file line numberDiff line numberDiff line change
@@ -1068,13 +1068,4 @@ public function testBug10228(): void
10681068
$this->analyse([__DIR__ . '/data/bug-10228.php'], []);
10691069
}
10701070

1071-
public function testBug9550(): void
1072-
{
1073-
$this->cliArgumentsVariablesRegistered = true;
1074-
$this->polluteScopeWithLoopInitialAssignments = false;
1075-
$this->checkMaybeUndefinedVariables = true;
1076-
$this->polluteScopeWithAlwaysIterableForeach = true;
1077-
$this->analyse([__DIR__ . '/data/bug-9550.php'], []);
1078-
}
1079-
10801071
}

tests/PHPStan/Rules/Variables/data/bug-9550.php

-32
This file was deleted.

0 commit comments

Comments
 (0)