From b53c2457761ec43dde1dc95d4c803d20e9a38957 Mon Sep 17 00:00:00 2001 From: Mark <> Date: Thu, 7 Nov 2024 21:28:19 +0100 Subject: [PATCH] fix empty ranges not being empty --- mers/Cargo.toml | 4 ++-- mers_lib/Cargo.toml | 2 +- mers_lib/src/program/configs/with_iters.rs | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mers/Cargo.toml b/mers/Cargo.toml index 5589f51..7d9b65f 100644 --- a/mers/Cargo.toml +++ b/mers/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mers" -version = "0.9.14" +version = "0.9.16" edition = "2021" license = "MIT OR Apache-2.0" description = "dynamically typed but type-checked programming language" @@ -15,7 +15,7 @@ default = ["colored-output"] colored-output = ["mers_lib/ecolor-term", "mers_lib/pretty-print", "dep:colored"] [dependencies] -mers_lib = "0.9.15" +mers_lib = "0.9.16" # mers_lib = { path = "../mers_lib" } clap = { version = "4.3.19", features = ["derive"] } colored = { version = "2.1.0", optional = true } diff --git a/mers_lib/Cargo.toml b/mers_lib/Cargo.toml index 80f354f..25d821a 100755 --- a/mers_lib/Cargo.toml +++ b/mers_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mers_lib" -version = "0.9.15" +version = "0.9.16" edition = "2021" license = "MIT OR Apache-2.0" description = "library to use the mers language in other projects" diff --git a/mers_lib/src/program/configs/with_iters.rs b/mers_lib/src/program/configs/with_iters.rs index db64dc3..bb9f657 100755 --- a/mers_lib/src/program/configs/with_iters.rs +++ b/mers_lib/src/program/configs/with_iters.rs @@ -721,7 +721,11 @@ impl MersType for RangeT { write!(f, "Range<{}..{}>", self.0, self.1) } fn iterable(&self) -> Option { - Some(Type::new(IntT(self.0, self.0.max(self.1)))) + Some(if self.is_empty() { + Type::empty() + } else { + Type::new(IntT(self.0, self.1)) + }) } fn is_same_type_as(&self, other: &dyn MersType) -> bool { other @@ -761,7 +765,7 @@ struct RangeInt(isize, isize, bool); impl Iterator for RangeInt { type Item = isize; fn next(&mut self) -> Option { - if !self.2 { + if !self.2 && self.0 <= self.1 { let o = self.0; if self.0 < self.1 { self.0 += 1;