From f7250dbe9b23415f02961edc5f34e3f084e2b659 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 16 Aug 2021 10:11:05 +0200 Subject: [PATCH] Fix TemplateTypeMap::isEmpty() --- src/Type/Generic/TemplateTypeMap.php | 4 ++-- tests/PHPStan/Type/Generic/TemplateTypeMapTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Type/Generic/TemplateTypeMap.php b/src/Type/Generic/TemplateTypeMap.php index 670b6a5f16..ec864bb171 100644 --- a/src/Type/Generic/TemplateTypeMap.php +++ b/src/Type/Generic/TemplateTypeMap.php @@ -65,12 +65,12 @@ public static function createEmpty(): self public function isEmpty(): bool { - return count($this->types) === 0; + return $this->count() === 0; } public function count(): int { - return count($this->types); + return count($this->types + $this->lowerBoundTypes); } /** @return array */ diff --git a/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php b/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php index 77c0c11b13..41ca7505c3 100644 --- a/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php +++ b/tests/PHPStan/Type/Generic/TemplateTypeMapTest.php @@ -15,6 +15,11 @@ public function dataUnionWithLowerBoundTypes(): iterable 'T' => new ObjectType(\Exception::class), ]))->convertToLowerBoundTypes(); + yield [ + $map, + \Exception::class, + ]; + yield [ $map->union(new TemplateTypeMap([ 'T' => new ObjectType(\InvalidArgumentException::class), @@ -51,6 +56,7 @@ public function dataUnionWithLowerBoundTypes(): iterable /** @dataProvider dataUnionWithLowerBoundTypes */ public function testUnionWithLowerBoundTypes(TemplateTypeMap $map, string $expectedTDescription): void { + $this->assertFalse($map->isEmpty()); $t = $map->getType('T'); $this->assertNotNull($t); $this->assertSame($expectedTDescription, $t->describe(VerbosityLevel::precise()));