From d101764ff94a5838930a11fdac7ca9156ded7dc4 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Tue, 1 Feb 2022 22:04:06 +0100 Subject: [PATCH] Fix segfault --- src/Type/IntersectionType.php | 3 +- .../Analyser/AnalyserIntegrationTest.php | 6 ++++ tests/PHPStan/Analyser/data/bug-6501.php | 34 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Analyser/data/bug-6501.php diff --git a/src/Type/IntersectionType.php b/src/Type/IntersectionType.php index 32331d84b9..956d385ccf 100644 --- a/src/Type/IntersectionType.php +++ b/src/Type/IntersectionType.php @@ -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; @@ -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); } diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 5d9b1d91cd..3de557c17b 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -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[] diff --git a/tests/PHPStan/Analyser/data/bug-6501.php b/tests/PHPStan/Analyser/data/bug-6501.php new file mode 100644 index 0000000000..4254ae62c8 --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-6501.php @@ -0,0 +1,34 @@ +