Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions src/Analyser/ExprHandler/ArrayDimFetchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: $varResult->isAlwaysTerminating(),
throwPoints: $varResult->getThrowPoints(),
impurePoints: $varResult->getImpurePoints(),
containsNullsafe: $varResult->containsNullsafe(),
);
}

Expand Down Expand Up @@ -123,6 +124,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: $dimResult->isAlwaysTerminating() || $varResult->isAlwaysTerminating(),
throwPoints: $throwPoints,
impurePoints: $impurePoints,
containsNullsafe: $varResult->containsNullsafe(),
);
}

Expand Down
1 change: 1 addition & 0 deletions src/Analyser/ExprHandler/MethodCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: $isAlwaysTerminating,
throwPoints: $throwPoints,
impurePoints: $impurePoints,
containsNullsafe: $varResult->containsNullsafe(),
);

$calledOnType = $originalScope->getType($expr->var);
Expand Down
1 change: 1 addition & 0 deletions src/Analyser/ExprHandler/NullsafeMethodCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: false,
throwPoints: $exprResult->getThrowPoints(),
impurePoints: $exprResult->getImpurePoints(),
containsNullsafe: true,
);
}

Expand Down
1 change: 1 addition & 0 deletions src/Analyser/ExprHandler/NullsafePropertyFetchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: false,
throwPoints: $exprResult->getThrowPoints(),
impurePoints: $exprResult->getImpurePoints(),
containsNullsafe: true,
);
}

Expand Down
1 change: 1 addition & 0 deletions src/Analyser/ExprHandler/PropertyFetchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: $isAlwaysTerminating,
throwPoints: $throwPoints,
impurePoints: $impurePoints,
containsNullsafe: $varResult->containsNullsafe(),
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Analyser/ExprHandler/StaticCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
$throwPoints = [];
$impurePoints = [];
$isAlwaysTerminating = false;
$containsNullsafe = false;
if ($expr->class instanceof Expr) {
$classResult = $nodeScopeResolver->processExprNode($stmt, $expr->class, $scope, $storage, $nodeCallback, $context->enterDeep());
$hasYield = $classResult->hasYield();
Expand All @@ -96,6 +97,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
$isAlwaysTerminating = $classResult->isAlwaysTerminating();

$scope = $classResult->getScope();
$containsNullsafe = $classResult->containsNullsafe();
}

$parametersAcceptor = null;
Expand Down Expand Up @@ -299,6 +301,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: $isAlwaysTerminating,
throwPoints: $throwPoints,
impurePoints: $impurePoints,
containsNullsafe: $containsNullsafe,
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Analyser/ExprHandler/StaticPropertyFetchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
),
];
$isAlwaysTerminating = false;
$containsNullsafe = false;
if ($expr->class instanceof Expr) {
$classResult = $nodeScopeResolver->processExprNode($stmt, $expr->class, $scope, $storage, $nodeCallback, $context->enterDeep());
$hasYield = $classResult->hasYield();
$throwPoints = $classResult->getThrowPoints();
$impurePoints = $classResult->getImpurePoints();
$isAlwaysTerminating = $classResult->isAlwaysTerminating();
$scope = $classResult->getScope();
$containsNullsafe = $classResult->containsNullsafe();
}
if (!$expr->name instanceof VarLikeIdentifier) {
$nameResult = $nodeScopeResolver->processExprNode($stmt, $expr->name, $scope, $storage, $nodeCallback, $context->enterDeep());
Expand All @@ -91,6 +93,7 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
isAlwaysTerminating: $isAlwaysTerminating,
throwPoints: $throwPoints,
impurePoints: $impurePoints,
containsNullsafe: $containsNullsafe,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Analyser/ExprHandler/VariableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
$isAlwaysTerminating,
$throwPoints,
$impurePoints,
static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
truthyScopeCallback: static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
falseyScopeCallback: static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Analyser/ExpressionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(
private bool $isAlwaysTerminating,
private array $throwPoints,
private array $impurePoints,
private bool $containsNullsafe = false,
?callable $truthyScopeCallback = null,
?callable $falseyScopeCallback = null,
)
Expand All @@ -57,6 +58,17 @@ public function hasYield(): bool
return $this->hasYield;
}

/**
* Whether this expression's chain contains a nullsafe operator (?->). A
* fetch/call on a receiver whose chain short-circuits propagates null,
* which a plain nullable receiver (e.g. a nullable variable) does not -
* this flag is what tells them apart.
*/
public function containsNullsafe(): bool
{
return $this->containsNullsafe;
}

/**
* @return InternalThrowPoint[]
*/
Expand Down
1 change: 1 addition & 0 deletions src/Analyser/ExpressionResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function create(
bool $isAlwaysTerminating,
array $throwPoints,
array $impurePoints,
bool $containsNullsafe = false,
?callable $truthyScopeCallback = null,
?callable $falseyScopeCallback = null,
): ExpressionResult;
Expand Down
Loading