Skip to content

Commit fe3a341

Browse files
committed
Fix NeverType::toBoolean()
1 parent 1ec1c91 commit fe3a341

File tree

5 files changed

+28
-5
lines changed

5 files changed

+28
-5
lines changed

src/Type/NeverType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
1313
use PHPStan\ShouldNotHappenException;
1414
use PHPStan\TrinaryLogic;
15-
use PHPStan\Type\Traits\FalseyBooleanTypeTrait;
1615
use PHPStan\Type\Traits\NonGenericTypeTrait;
16+
use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
1717
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;
1818

1919
/** @api */
2020
class NeverType implements CompoundType
2121
{
2222

23-
use FalseyBooleanTypeTrait;
23+
use UndecidedBooleanTypeTrait;
2424
use NonGenericTypeTrait;
2525
use UndecidedComparisonCompoundTypeTrait;
2626

tests/PHPStan/Rules/Comparison/BooleanAndConstantConditionRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testRule(): void
5656
27,
5757
],
5858
[
59-
'Right side of && is always false.',
59+
'Result of && is always false.',
6060
30,
6161
],
6262
[

tests/PHPStan/Rules/Comparison/BooleanOrConstantConditionRuleTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testRule(): void
6060
30,
6161
],
6262
[
63-
'Right side of || is always false.',
63+
'Result of || is always true.',
6464
33,
6565
],
6666
[
@@ -175,4 +175,10 @@ public function testTreatPhpDocTypesAsCertainRegression(bool $treatPhpDocTypesAs
175175
$this->analyse([__DIR__ . '/data/boolean-or-treat-phpdoc-types-regression.php'], []);
176176
}
177177

178+
public function testBug6258(): void
179+
{
180+
$this->treatPhpDocTypesAsCertain = true;
181+
$this->analyse([__DIR__ . '/data/bug-6258.php'], []);
182+
}
183+
178184
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug6258;
4+
5+
defined('a') || die();
6+
defined('a') or die();
7+
rand() === rand() || die();
8+
9+
10+
defined('a') || exit();
11+
defined('a') or exit();
12+
rand() === rand() || exit();
13+
14+
15+
defined('a') || throw new \Exception('');
16+
defined('a') or throw new \Exception('');
17+
rand() === rand() || throw new \Exception('');

tests/PHPStan/Type/IntersectionTypeTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ public function testIsSubTypeOfInversed(IntersectionType $type, Type $otherType,
396396
public function testToBooleanCrash(): void
397397
{
398398
$type = new IntersectionType([new NeverType(), new NonEmptyArrayType()]);
399-
$this->assertSame('bool', $type->toBoolean()->describe(VerbosityLevel::precise()));
399+
$this->assertSame('true', $type->toBoolean()->describe(VerbosityLevel::precise()));
400400
}
401401

402402
}

0 commit comments

Comments
 (0)