Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@ public function testBug10884(): void
$this->analyse([__DIR__ . '/data/bug-10884.php'], []);
}

public function testBug3761(): void
{
$this->analyse([__DIR__ . '/data/bug-3761.php'], []);
}

public function testBug13208(): void
{
$this->analyse([__DIR__ . '/data/bug-13208.php'], []);
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-3761.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types = 1);

namespace Bug3761;

class NamedTag{
public function getValue() : int{
return 1;
}
}

class SubclassOfNamedTag extends NamedTag{}

class OtherSubclassOfNamedTag extends NamedTag{}

class HelloWorld
{
public function getTag() : ?NamedTag{
return new SubclassOfNamedTag();
}

/**
* @phpstan-param class-string<NamedTag> $class
*/
public function getTagValue(string $class = NamedTag::class) : int{
$tag = $this->getTag();
if($tag instanceof $class){
return $tag->getValue();
}

throw new \RuntimeException(($tag === null ? "Missing" : get_class($tag)));
}
}

(new HelloWorld())->getTagValue(OtherSubclassOfNamedTag::class); //runtime exception: SubclassOfNamedTag
Loading