Make range-end exclusive

This commit is contained in:
Laurenz 2021-08-12 14:54:52 +02:00
parent eaa3cbaa9c
commit ccb4be4da4
4 changed files with 8 additions and 8 deletions

View File

@ -247,7 +247,7 @@ comparison!(geq, ">=", Ordering::Greater | Ordering::Equal);
/// Compute the range from `lhs` to `rhs`. /// Compute the range from `lhs` to `rhs`.
pub fn range(lhs: Value, rhs: Value) -> StrResult<Value> { pub fn range(lhs: Value, rhs: Value) -> StrResult<Value> {
match (lhs, rhs) { match (lhs, rhs) {
(Int(a), Int(b)) => Ok(Array((a ..= b).map(Int).collect())), (Int(a), Int(b)) => Ok(Array((a .. b).map(Int).collect())),
(a, b) => mismatch!("cannot apply '..' to {} and {}", a, b), (a, b) => mismatch!("cannot apply '..' to {} and {}", a, b),
} }
} }

View File

@ -278,7 +278,7 @@ pub enum BinOp {
MulAssign, MulAssign,
/// The divide-assign operator: `/=`. /// The divide-assign operator: `/=`.
DivAssign, DivAssign,
/// The inclusive range operator: `..`. /// The range operator: `..`.
Range, Range,
} }

View File

@ -53,7 +53,7 @@
--- ---
{ {
let x = 2 let x = 2
for _ in 0..60 { for _ in 0..61 {
x *= 2 x *= 2
} }
// Error: 4-18 cannot repeat this string 4611686018427387904 times // Error: 4-18 cannot repeat this string 4611686018427387904 times

View File

@ -163,12 +163,12 @@
// Test range operator. // Test range operator.
#let array = (1, 2, 3) #let array = (1, 2, 3)
#test(1..3, array) #test(1..4, array)
#test(1.. 3, array) #test(1.. 4, array)
#test(1 ..3, array) #test(1 ..4, array)
#test(1 .. 3, array) #test(1 .. 4, array)
#test(-4..2, (-4, -3, -2, -1, 0, 1, 2)) #test(-4..2, (-4, -3, -2, -1, 0, 1))
#test(10..5, ()) #test(10..5, ())
--- ---