Skip to content

Commit 310cb83

Browse files
committed
Merging scopes in root scope - create maybe-existent variables from the other scope too
1 parent aa2907d commit 310cb83

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

src/Analyser/MutatingScope.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,14 @@ public function mergeWith(?self $otherScope): self
33533353

33543354
$ourVariableTypes[$name] = VariableTypeHolder::createMaybe(new MixedType());
33553355
}
3356+
3357+
foreach (array_keys($ourVariableTypes) as $name) {
3358+
if (array_key_exists($name, $theirVariableTypes)) {
3359+
continue;
3360+
}
3361+
3362+
$theirVariableTypes[$name] = VariableTypeHolder::createMaybe(new MixedType());
3363+
}
33563364
}
33573365

33583366
return $this->scopeFactory->create(

tests/PHPStan/Rules/DeadCode/UnreachableStatementRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ public function testBugWithoutGitHubIssue1(bool $treatPhpDocTypesAsCertain): voi
8080
$this->analyse([__DIR__ . '/data/bug-without-issue-1.php'], []);
8181
}
8282

83+
public function testBug4070(): void
84+
{
85+
$this->treatPhpDocTypesAsCertain = true;
86+
$this->analyse([__DIR__ . '/data/bug-4070.php'], []);
87+
}
88+
89+
public function testBug4070Two(): void
90+
{
91+
$this->treatPhpDocTypesAsCertain = true;
92+
$this->analyse([__DIR__ . '/data/bug-4070_2.php'], []);
93+
}
94+
8395
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug4070;
4+
5+
array_shift($argv);
6+
7+
while ($argv) {
8+
$arg = array_shift($argv);
9+
if ($arg === 'foo') {
10+
continue;
11+
}
12+
die();
13+
}
14+
15+
echo "finished\n";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug4070Two;
4+
5+
function () {
6+
array_shift($argv);
7+
8+
while ($argv) {
9+
$arg = array_shift($argv);
10+
if ($arg === 'foo') {
11+
continue;
12+
}
13+
die();
14+
}
15+
16+
echo "finished\n";
17+
};

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,6 @@ public function testUnpackOperator(): void
398398
public function testFunctionWithNumericParameterThatCreatedByAddition(): void
399399
{
400400
$this->analyse([__DIR__ . '/data/function-with-int-parameter-that-created-by-addition.php'], [
401-
[
402-
'Parameter #1 $num of function dechex expects int, float|int given.',
403-
9,
404-
],
405401
[
406402
'Parameter #1 $num of function dechex expects int, float|int given.',
407403
40,

0 commit comments

Comments
 (0)