Skip to content

Commit

Permalink
Fix NeverType::toBoolean()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 1, 2022
1 parent 1ec1c91 commit fe3a341
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Type/NeverType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Traits\FalseyBooleanTypeTrait;
use PHPStan\Type\Traits\NonGenericTypeTrait;
use PHPStan\Type\Traits\UndecidedBooleanTypeTrait;
use PHPStan\Type\Traits\UndecidedComparisonCompoundTypeTrait;

/** @api */
class NeverType implements CompoundType
{

use FalseyBooleanTypeTrait;
use UndecidedBooleanTypeTrait;
use NonGenericTypeTrait;
use UndecidedComparisonCompoundTypeTrait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testRule(): void
27,
],
[
'Right side of && is always false.',
'Result of && is always false.',
30,
],
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testRule(): void
30,
],
[
'Right side of || is always false.',
'Result of || is always true.',
33,
],
[
Expand Down Expand Up @@ -175,4 +175,10 @@ public function testTreatPhpDocTypesAsCertainRegression(bool $treatPhpDocTypesAs
$this->analyse([__DIR__ . '/data/boolean-or-treat-phpdoc-types-regression.php'], []);
}

public function testBug6258(): void
{
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/data/bug-6258.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-6258.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Bug6258;

defined('a') || die();
defined('a') or die();
rand() === rand() || die();


defined('a') || exit();
defined('a') or exit();
rand() === rand() || exit();


defined('a') || throw new \Exception('');
defined('a') or throw new \Exception('');
rand() === rand() || throw new \Exception('');
2 changes: 1 addition & 1 deletion tests/PHPStan/Type/IntersectionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function testIsSubTypeOfInversed(IntersectionType $type, Type $otherType,
public function testToBooleanCrash(): void
{
$type = new IntersectionType([new NeverType(), new NonEmptyArrayType()]);
$this->assertSame('bool', $type->toBoolean()->describe(VerbosityLevel::precise()));
$this->assertSame('true', $type->toBoolean()->describe(VerbosityLevel::precise()));
}

}

0 comments on commit fe3a341

Please sign in to comment.