diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index cfd8ce1d2..f8e737489 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -863,6 +863,10 @@ class TypeParser return new TPositiveInt(); } + if (is_int($min_bound) && is_int($max_bound) && $min_bound > $max_bound) { + throw new TypeParseTreeException("Min bound can't be greater than max bound"); + } + return new TIntRange($min_bound, $max_bound); } diff --git a/tests/IntRangeTest.php b/tests/IntRangeTest.php index 2595f7660..d8d26c751 100644 --- a/tests/IntRangeTest.php +++ b/tests/IntRangeTest.php @@ -798,6 +798,16 @@ class IntRangeTest extends TestCase }', 'error_message' => 'InvalidDocblock', ], + 'minGreaterThanMax' => [ + ' $a + */ + function scope(int $a){ + return $a; + }', + 'error_message' => 'InvalidDocblock', + ], ]; } }