Skip to content

Commit f638910

Browse files
committed
Merge branch 2.1.x into 2.2.x
2 parents d5bc2e7 + 7861fe4 commit f638910

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

src/Analyser/ExprHandler/NewHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
131131
$constructorResult = $node;
132132
}, StatementContext::createTopLevel());
133133
if ($constructorResult !== null) {
134-
$throwPoints = array_map(static fn (ThrowPoint $point) => InternalThrowPoint::createFromPublic($point), $constructorResult->getStatementResult()->getThrowPoints());
134+
$throwPoints = array_map(static fn (ThrowPoint $point): InternalThrowPoint => InternalThrowPoint::createFromPublic($point, $scope), $constructorResult->getStatementResult()->getThrowPoints());
135135
$impurePoints = $constructorResult->getImpurePoints();
136136
}
137137
} else {

src/Analyser/InternalThrowPoint.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Analyser;
44

55
use PhpParser\Node;
6-
use PHPStan\ShouldNotHappenException;
76
use PHPStan\Type\ObjectType;
87
use PHPStan\Type\Type;
98
use PHPStan\Type\TypeCombinator;
@@ -50,13 +49,8 @@ public static function createImplicit(MutatingScope $scope, Node $node): self
5049
return new self($scope, new ObjectType(Throwable::class), $node, explicit: false, canContainAnyThrowable: true);
5150
}
5251

53-
public static function createFromPublic(ThrowPoint $throwPoint): self
52+
public static function createFromPublic(ThrowPoint $throwPoint, MutatingScope $scope): self
5453
{
55-
$scope = $throwPoint->getScope();
56-
if (!$scope instanceof MutatingScope) {
57-
throw new ShouldNotHappenException();
58-
}
59-
6054
return new self($scope, $throwPoint->getType(), $throwPoint->getNode(), $throwPoint->isExplicit(), $throwPoint->canContainAnyThrowable());
6155
}
6256

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,16 @@ public function testBug12373(): void
14441444
$this->analyse([__DIR__ . '/data/bug-12373.php'], []);
14451445
}
14461446

1447+
public function testBug13920(): void
1448+
{
1449+
$this->cliArgumentsVariablesRegistered = true;
1450+
$this->polluteScopeWithLoopInitialAssignments = true;
1451+
$this->checkMaybeUndefinedVariables = true;
1452+
$this->polluteScopeWithAlwaysIterableForeach = true;
1453+
1454+
$this->analyse([__DIR__ . '/data/bug-13920.php'], []);
1455+
}
1456+
14471457
public function testBug14117(): void
14481458
{
14491459
$this->cliArgumentsVariablesRegistered = true;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug13920;
4+
5+
class TestOutput {
6+
public function __construct() {}
7+
}
8+
9+
final class MyTest
10+
{
11+
public function testRun(): void
12+
{
13+
$savedArgv = $_SERVER['argv'];
14+
15+
try {
16+
$output = new class() extends TestOutput {
17+
public function __construct()
18+
{
19+
parent::__construct();
20+
}
21+
};
22+
} finally {
23+
$_SERVER['argv'] = $savedArgv;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)