Skip to content

Commit

Permalink
Regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 17, 2021
1 parent 863dde2 commit 775c3f3
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Expand Up @@ -479,4 +479,14 @@ public function testBug3120(): void
$this->analyse([__DIR__ . '/data/bug-3120.php'], []);
}

public function testBug3118(): void
{
$this->analyse([__DIR__ . '/data/bug-3118.php'], [
[
'Method Bug3118\CustomEnum2::all() should return Bug3118\EnumSet<static(Bug3118\CustomEnum2)> but returns Bug3118\CustomEnumSet.',
56,
],
]);
}

}
58 changes: 58 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3118.php
@@ -0,0 +1,58 @@
<?php

namespace Bug3118;

/**
* @template T of Enum
*/
class EnumSet
{
private $type;

/**
* @param class-string<T> $type
*/
public function __construct(string $type)
{
$this->type = $type;
}
}

abstract class Enum
{
/**
* @return EnumSet<static>
*/
public static function all(): EnumSet
{
return new EnumSet(static::class);
}
}

/**
* @extends EnumSet<CustomEnum>
*/
final class CustomEnumSet extends EnumSet
{

public function __construct()
{
parent::__construct(CustomEnum::class);
}
}

final class CustomEnum extends Enum
{
public static function all(): EnumSet
{
return new CustomEnumSet();
}
}

class CustomEnum2 extends Enum
{
public static function all(): EnumSet
{
return new CustomEnumSet();
}
}

0 comments on commit 775c3f3

Please sign in to comment.