Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 27, 2023
1 parent 0177e33 commit 8ae98de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function dataFileAsserts(): iterable
if (PHP_VERSION_ID >= 80100) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/generic-enum-class-string.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7162.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10201.php');
}

require_once __DIR__ . '/data/generic-generalization.php';
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Analyser/data/bug-10201.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php // lint >= 8.1

namespace Bug10201;

use function PHPStan\Testing\assertType;

enum Hello
{
case Hi;
}

function bla(null|string|Hello $hello): void {
if (!in_array($hello, [Hello::Hi, null], true) && !($hello instanceof Hello)) {
assertType('string', $hello);
}
}

function bla2(null|string|Hello $hello): void {
if (!in_array($hello, [Hello::Hi, null], true)) {
assertType('string', $hello);
}
}
12 changes: 12 additions & 0 deletions tests/PHPStan/Rules/Classes/ImpossibleInstanceOfRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,4 +589,16 @@ public function testReportAlwaysTrueInLastCondition(bool $reportAlwaysTrueInLast
$this->analyse([__DIR__ . '/data/impossible-instanceof-report-always-true-last-condition.php'], $expectedErrors);
}

public function testBug10201(): void
{
$this->checkAlwaysTrueInstanceOf = true;
$this->treatPhpDocTypesAsCertain = true;
$this->analyse([__DIR__ . '/../../Analyser/data/bug-10201.php'], [
[
'Instanceof between string and Bug10201\Hello will always evaluate to false.',
13,
],
]);
}

}

0 comments on commit 8ae98de

Please sign in to comment.