Skip to content
Closed
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: 1 addition & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3692,7 +3692,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto

$rightScope = $scope->filterByFalseyValue($expr);
$rightResult = $this->processExprNode($stmt, $expr->right, $rightScope, $storage, $nodeCallback, $context->enterDeep());
$rightExprType = $scope->getType($expr->right);
$rightExprType = $expr->right instanceof Coalesce ? null : $scope->getType($expr->right);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems really specific,

  • this at least need a comment
  • and maybe they is more case to skip ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It could be better maybe but it solves the problem. I recently did the same fix with Ternary.

if ($rightExprType instanceof NeverType && $rightExprType->isExplicit()) {
$scope = $scope->filterByTruthyValue(new Expr\Isset_([$expr->left]));
} else {
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,12 @@ public function testBug14207And(): void
$this->assertNoErrors($errors);
}

public function testBug14214(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-14214.php');
$this->assertNoErrors($errors);
}

public function testBug13945(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-13945.php');
Expand Down
88 changes: 88 additions & 0 deletions tests/PHPStan/Analyser/data/bug-14214.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php declare(strict_types = 1);

namespace Bug14214;

use function PHPStan\Testing\assertType;

class HelloWorld
{
public static function is_too_slow(): void
{
$x0 = $x1 = $x2 = $x3 = $x4 = $x5 = $x6 = $x7 = $x8 = $x9 = $x10 = null;
$x11 = $x12 = $x13 = $x14 = $x15 = $x16 = null;

if (rand(0, 1)) {
$x0 = rand(0, 1);
}
if (rand(0, 1)) {
$x1 = rand(2, 3);
}
if (rand(0, 1)) {
$x2 = rand(4, 5);
}
if (rand(0, 1)) {
$x3 = rand(6, 7);
}
if (rand(0, 1)) {
$x4 = rand(8, 9);
}
if (rand(0, 1)) {
$x5 = rand(10, 11);
}
if (rand(0, 1)) {
$x6 = rand(12, 13);
}
if (rand(0, 1)) {
$x7 = rand(14, 15);
}
if (rand(0, 1)) {
$x8 = rand(16, 17);
}
if (rand(0, 1)) {
$x9 = rand(18, 19);
}
if (rand(0, 1)) {
$x10 = rand(20, 21);
}
if (rand(0, 1)) {
$x11 = rand(22, 23);
}
if (rand(0, 1)) {
$x12 = rand(24, 25);
}
if (rand(0, 1)) {
$x13 = rand(26, 27);
}
if (rand(0, 1)) {
$x14 = rand(28, 29);
}
if (rand(0, 1)) {
$x15 = rand(30, 31);
}
if (rand(0, 1)) {
$x16 = rand(32, 33);
}

$x = (
$x0 ??
$x1 ??
$x2 ??
$x3 ??
$x4 ??
$x5 ??
$x6 ??
$x7 ??
$x8 ??
$x9 ??
$x10 ??
$x11 ??
$x12 ??
$x13 ??
$x14 ??
$x15 ??
$x16
);

assertType('int<0, 33>|null', $x);
}
}
Loading