Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb authored and ondrejmirtes committed Feb 4, 2022
1 parent 9512513 commit 705b460
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Type/UnionType.php
Expand Up @@ -101,6 +101,10 @@ public function accepts(Type $type, bool $strictTypes): TrinaryLogic
$results[] = $innerType->accepts($type, $strictTypes);
}

if ($type instanceof TemplateUnionType) {
$results[] = $type->isAcceptedBy($this, $strictTypes);
}

return TrinaryLogic::createNo()->or(...$results);
}

Expand All @@ -118,6 +122,10 @@ public function isSuperTypeOf(Type $otherType): TrinaryLogic
$results[] = $innerType->isSuperTypeOf($otherType);
}

if ($otherType instanceof TemplateUnionType) {
$results[] = $otherType->isSubTypeOf($this);
}

return TrinaryLogic::createNo()->or(...$results);
}

Expand Down
33 changes: 33 additions & 0 deletions tests/PHPStan/Type/UnionTypeTest.php
Expand Up @@ -345,6 +345,23 @@ public function dataIsSuperTypeOf(): Iterator
TrinaryLogic::createNo(),
];

yield 'is super type of template-of-union with same members' => [
new UnionType([
new IntegerType(),
new FloatType(),
]),
TemplateTypeFactory::create(
TemplateTypeScope::createWithClass('Foo'),
'T',
new UnionType([
new IntegerType(),
new FloatType(),
]),
TemplateTypeVariance::createInvariant(),
),
TrinaryLogic::createYes(),
];

yield 'is super type of template-of-union equal to a union member' => [
new UnionType([
TemplateTypeFactory::create(
Expand Down Expand Up @@ -862,6 +879,22 @@ public function dataAccepts(): array
new ClosureType([], new MixedType(), false),
TrinaryLogic::createYes(),
],
'accepts template-of-union with same members' => [
new UnionType([
new IntegerType(),
new FloatType(),
]),
TemplateTypeFactory::create(
TemplateTypeScope::createWithClass('Foo'),
'T',
new UnionType([
new IntegerType(),
new FloatType(),
]),
TemplateTypeVariance::createInvariant(),
),
TrinaryLogic::createYes(),
],
'accepts template-of-union equal to a union member' => [
new UnionType([
TemplateTypeFactory::create(
Expand Down

0 comments on commit 705b460

Please sign in to comment.