1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Forbid min bound greater than max bound in int range

This commit is contained in:
Semyon 2022-03-11 17:26:59 +03:00
parent a7e98f4bfc
commit 9beb0a62b2
2 changed files with 14 additions and 0 deletions

View File

@ -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);
}

View File

@ -798,6 +798,16 @@ class IntRangeTest extends TestCase
}',
'error_message' => 'InvalidDocblock',
],
'minGreaterThanMax' => [
'<?php
/**
* @param int<4, 3> $a
*/
function scope(int $a){
return $a;
}',
'error_message' => 'InvalidDocblock',
],
];
}
}