Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 5, 2022
1 parent c05ba98 commit 7d4fa3d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ public function dataFileAsserts(): iterable
if (PHP_VERSION_ID >= 70400) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/nullable-closure-parameter.php');
}
if (PHP_VERSION_ID >= 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Methods/data/bug-6635.php');
}
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6584.php');
}

Expand Down
20 changes: 20 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,24 @@ public function testBug6353(): void
$this->analyse([__DIR__ . '/data/bug-6353.php'], []);
}

public function testBug6635Level9(): void
{
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-6635.php'], []);
}

public function testBug6635Level8(): void
{
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires PHP 8.0.');
}

$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/data/bug-6635.php'], []);
}

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

namespace Bug6635;

use function PHPStan\Testing\assertType;

interface A {
public function getValue(): int;
}

class HelloWorld
{
/**
* @template T
*
* @param T $block
*
* @return T
*/
protected function sayHelloBug(mixed $block): mixed {
assertType('T (method Bug6635\HelloWorld::sayHelloBug(), argument)', $block);
if ($block instanceof A) {
assertType('Bug6635\A&T (method Bug6635\HelloWorld::sayHelloBug(), argument)', $block);
echo 1;
} else {
assertType('T (method Bug6635\HelloWorld::sayHelloBug(), argument)', $block);
}

assertType('(Bug6635\A&T (method Bug6635\HelloWorld::sayHelloBug(), argument))|T (method Bug6635\HelloWorld::sayHelloBug(), argument)', $block);

return $block;
}
}

0 comments on commit 7d4fa3d

Please sign in to comment.