From 6ce32a48d5863aecc0d1d420f5867e8d45bed440 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 27 Jul 2022 20:24:24 +0200 Subject: [PATCH] Fix --- src/Psalm/Type.php | 7 ++++++- tests/TypeParseTest.php | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index 7c4493154..f08d10354 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -697,8 +697,13 @@ abstract class Type TIntRange::convertToIntRange($type_1_atomic), TIntRange::convertToIntRange($type_2_atomic) ); - if ($intersection_atomic) { + if ($intersection_atomic + && ($intersection_atomic->min_bound !== null || $intersection_atomic->max_bound !== null) + ) { $intersection_performed = true; + if ($intersection_atomic->min_bound === $intersection_atomic->max_bound) { + return new TLiteralInt($intersection_atomic->min_bound); + } return $intersection_atomic; } } diff --git a/tests/TypeParseTest.php b/tests/TypeParseTest.php index 36efc50a5..b6fdb3e0b 100644 --- a/tests/TypeParseTest.php +++ b/tests/TypeParseTest.php @@ -213,6 +213,13 @@ class TypeParseTest extends TestCase $this->assertSame('array{a: int}', (string) Type::parseString('array{a: int}&array{a?: int}')); } + + public function testIntersectionOfIntranges(): void + { + $this->assertSame('array{a: int<3, 4>}', (string) Type::parseString('array{a: int<2, 4>}&array{a: int<3, 6>}')); + $this->assertSame('array{a: 4}', Type::parseString('array{a: 4}&array{a: int<3, 6>}')->getId(true)); + } + public function testIntersectionOfTKeyedArrayWithConflictingProperties(): void { $this->expectException(TypeParseTreeException::class);