Skip to content

Commit

Permalink
Fix segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 1, 2022
1 parent 6284d4e commit d101764
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Type/IntersectionType.php
Expand Up @@ -19,6 +19,7 @@
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\Accessory\AccessoryType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use function array_map;
Expand Down Expand Up @@ -96,7 +97,7 @@ public function isSuperTypeOf(Type $otherType): TrinaryLogic

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
if ($otherType instanceof self || $otherType instanceof UnionType) {
if (($otherType instanceof self || $otherType instanceof UnionType) && !$otherType instanceof TemplateType) {
return $otherType->isSuperTypeOf($this);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Expand Up @@ -535,6 +535,12 @@ public function testBug6375(): void
$this->assertNoErrors($errors);
}

public function testBug6501(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6501.php');
$this->assertNoErrors($errors);
}

/**
* @param string[]|null $allAnalysedFiles
* @return Error[]
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/Analyser/data/bug-6501.php
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Bug6501;

/**
* @template T of \stdClass
* @template R of \stdClass|\Exception
*/
abstract class AbstractWithOptionsHydrator
{
/** @var string */
protected const OPTION_OWNER_PROPERTY = '';

/**
* @param T $entity
*
* @return R
*/
protected function hydrateOption(\stdClass $entity)
{
/** @var R $option */
$option = new \stdClass();
$callable = [$option, 'set' . static::OPTION_OWNER_PROPERTY];
if (!is_callable($callable)) {
return $option;
}

call_user_func($callable, $entity);

return $option;
}
}

0 comments on commit d101764

Please sign in to comment.