Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3877,7 +3877,7 @@ public function processAlwaysIterableForeachScopeWithoutPollute(self $finalScope
$this->getNamespace(),
$expressionTypes,
$nativeTypes,
$this->conditionalExpressions,
$finalScope->conditionalExpressions,
$this->inClosureBindScopeClasses,
$this->anonymousFunctionReflection,
$this->inFirstLevelStatement,
Expand Down
36 changes: 36 additions & 0 deletions tests/PHPStan/Analyser/Bug14446Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php declare(strict_types = 1);

namespace PHPStan\Analyser;

use PHPStan\Testing\TypeInferenceTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

class Bug14446Test extends TypeInferenceTestCase
{

public static function dataFileAsserts(): iterable
{
yield from self::gatherAssertTypes(__DIR__ . '/data/bug-14446.php');
}

/**
* @param mixed ...$args
*/
#[DataProvider('dataFileAsserts')]
public function testFileAsserts(
string $assertType,
string $file,
...$args,
): void
{
$this->assertFileAsserts($assertType, $file, ...$args);
}

public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/bug-14446.neon',
];
}

}
2 changes: 2 additions & 0 deletions tests/PHPStan/Analyser/bug-14446.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
Copy link
Copy Markdown
Contributor

@staabm staabm Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this test be in the strict-rule repo instead?
OverwriteVariablesWithForeachRuleTest

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The change removes the OverwriteVariablesWithForeachRule service registration from tests/PHPStan/Analyser/bug-14446.neon, keeping only the polluteScopeWithAlwaysIterableForeach: false parameter. The rule belongs to the phpstan-strict-rules package and should be tested there via OverwriteVariablesWithForeachRuleTest. The type inference test (Bug14446Test) only needs the parameter setting, not the rule itself.

Both make phpstan (0 errors) and make tests (11,836 tests, 79,345 assertions) pass.

polluteScopeWithAlwaysIterableForeach: false
24 changes: 24 additions & 0 deletions tests/PHPStan/Analyser/data/bug-14446.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php declare(strict_types = 1);

namespace Bug14446;

use function PHPStan\Testing\assertType;

function test(bool $initial): void {
$current = $initial;

while (true) {
assertType('bool', $initial);
if (!$current) {
assertType('bool', $initial);
break;
}

$items = [1];
foreach ($items as $item) {
$current = false;
}
}

assertType('bool', $initial);
}
Loading