Skip to content
Merged
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
12 changes: 6 additions & 6 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2017,18 +2017,18 @@ private function createForExpr(
$sureNotTypes = [];
if ($context->false()) {
$exprString = $this->exprPrinter->printExpr($expr);
$originalExprString = $this->exprPrinter->printExpr($originalExpr);

$sureNotTypes[$exprString] = [$expr, $type];
if ($exprString !== $originalExprString) {

if ($expr !== $originalExpr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really saving calls ? The code was comparing the string but now you are comparing the expr.

Also should you still check string after in case two expr has the same string print ? (Dunno if its possible)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the PR description with a diff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the 2 expressions involved can be compared this way, because they originate from a assignment a few lines above

https://github.com/phpstan/phpstan-src/pull/5018/files#diff-1076e38598f300a69c9dc998dae31374052f95bd69d0d71c11e9d0a4c188976dL1933

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also note that even if we theoretically would preduce the same string again, we would overwrite the previous existing value with the very same touple again

$originalExprString = $this->exprPrinter->printExpr($originalExpr);
$sureNotTypes[$originalExprString] = [$originalExpr, $type];
}
} elseif ($context->true()) {
$exprString = $this->exprPrinter->printExpr($expr);
$originalExprString = $this->exprPrinter->printExpr($originalExpr);

$sureTypes[$exprString] = [$expr, $type];
if ($exprString !== $originalExprString) {

if ($expr !== $originalExpr) {
$originalExprString = $this->exprPrinter->printExpr($originalExpr);
$sureTypes[$originalExprString] = [$originalExpr, $type];
}
}
Expand Down
Loading