Fix spurious error nullCoalesce.offset#5145
Conversation
|
You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x. |
|
This pull request has been marked as ready for review. |
fb95750 to
3b180d2
Compare
|
This pull request has been marked as ready for review. |
|
remaining errors also happen on 2.1.x - so seem unrelated |
|
|
||
| return new EnsuredNonNullabilityResult($scope, [ | ||
| new EnsuredNonNullabilityResultExpression($exprToSpecify, $originalExprType, $originalNativeType, $certainty), | ||
| new EnsuredNonNullabilityResultExpression($exprToSpecify, $originalExprType, $originalNativeType, $hasExpressionType), |
There was a problem hiding this comment.
Do we still need $certainty var ?
There was a problem hiding this comment.
yes - its used a few lines below
There was a problem hiding this comment.
We could maybe move the block
// keep certainty
$certainty = TrinaryLogic::createYes();
$hasExpressionType = $originalScope->hasExpressionType($exprToSpecify);
if (!$hasExpressionType->no()) {
$certainty = $hasExpressionType;
}
where it's used in order to avoid those check when they are not needed, but it doesn't cost a lot i think.
| $scope->getType($parentExpr), | ||
| $scope->getNativeType($parentExpr), | ||
| $parentCertainty, | ||
| $hasParentExpressionType, |
There was a problem hiding this comment.
Do we still need $parentCertainty var ?
|
|
||
| return new EnsuredNonNullabilityResult($scope, [ | ||
| new EnsuredNonNullabilityResultExpression($exprToSpecify, $originalExprType, $originalNativeType, $certainty), | ||
| new EnsuredNonNullabilityResultExpression($exprToSpecify, $originalExprType, $originalNativeType, $hasExpressionType), |
There was a problem hiding this comment.
We could maybe move the block
// keep certainty
$certainty = TrinaryLogic::createYes();
$hasExpressionType = $originalScope->hasExpressionType($exprToSpecify);
if (!$hasExpressionType->no()) {
$certainty = $hasExpressionType;
}
where it's used in order to avoid those check when they are not needed, but it doesn't cost a lot i think.
we need I think its already as easy as it can get thank you. |
|
aahh I finally understood what you mean :-) |
before this PR we only remembered maybe/yes expr certainty when restoring expressions.
this lead to that previously not-existing expressions (no-certainy) where restored into a yes-certainty instead of the state before.
closes phpstan/phpstan#13921
refs phpstan/phpstan#10305 (comment) (fixes a issue mentioned in comments but not the issue itself)