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/ExprHandler/NewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
$constructorResult = $node;
}, StatementContext::createTopLevel());
if ($constructorResult !== null) {
$throwPoints = array_map(static fn (ThrowPoint $point): InternalThrowPoint => InternalThrowPoint::createFromPublic($point)->replaceScope($scope), $constructorResult->getStatementResult()->getThrowPoints());
$throwPoints = array_map(static fn (ThrowPoint $point): InternalThrowPoint => InternalThrowPoint::createFromPublic($point, $scope), $constructorResult->getStatementResult()->getThrowPoints());
$impurePoints = $constructorResult->getImpurePoints();
}
} else {
Expand Down
15 changes: 6 additions & 9 deletions src/Analyser/InternalThrowPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public static function createImplicit(MutatingScope $scope, Node $node): self
return new self($scope, new ObjectType(Throwable::class), $node, explicit: false, canContainAnyThrowable: true);
}

public static function createFromPublic(ThrowPoint $throwPoint): self
public static function createFromPublic(ThrowPoint $throwPoint, ?MutatingScope $scope = null): self
Copy link
Contributor

Choose a reason for hiding this comment

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

the $scope parameter is not optional and cannot be null.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Already handled — all 11,571 tests passed, and the fix has been committed and pushed.

{
$scope = $throwPoint->getScope();
if (!$scope instanceof MutatingScope) {
throw new ShouldNotHappenException();
if ($scope === null) {
$scope = $throwPoint->getScope();
if (!$scope instanceof MutatingScope) {
throw new ShouldNotHappenException();
}
}

return new self($scope, $throwPoint->getType(), $throwPoint->getNode(), $throwPoint->isExplicit(), $throwPoint->canContainAnyThrowable());
Expand Down Expand Up @@ -88,11 +90,6 @@ public function canContainAnyThrowable(): bool
return $this->canContainAnyThrowable;
}

public function replaceScope(MutatingScope $scope): self
{
return new self($scope, $this->type, $this->node, $this->explicit, $this->canContainAnyThrowable);
}

public function subtractCatchType(Type $catchType): self
{
return new self($this->scope, TypeCombinator::remove($this->type, $catchType), $this->node, $this->explicit, $this->canContainAnyThrowable);
Expand Down
Loading