fix negative ranges

This commit is contained in:
Mark 2024-11-07 21:34:29 +01:00
parent b53c245776
commit 6630542644
3 changed files with 12 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mers" name = "mers"
version = "0.9.16" version = "0.9.17"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "dynamically typed but type-checked programming language" 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"] colored-output = ["mers_lib/ecolor-term", "mers_lib/pretty-print", "dep:colored"]
[dependencies] [dependencies]
mers_lib = "0.9.16" mers_lib = "0.9.17"
# mers_lib = { path = "../mers_lib" } # mers_lib = { path = "../mers_lib" }
clap = { version = "4.3.19", features = ["derive"] } clap = { version = "4.3.19", features = ["derive"] }
colored = { version = "2.1.0", optional = true } colored = { version = "2.1.0", optional = true }

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mers_lib" name = "mers_lib"
version = "0.9.16" version = "0.9.17"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "library to use the mers language in other projects" description = "library to use the mers language in other projects"

View File

@ -51,11 +51,14 @@ impl Config {
if a.0.len() == 2 { if a.0.len() == 2 {
let mut min = None; let mut min = None;
let mut max = None; let mut max = None;
for v in a.0[0].types.iter().chain(a.0[1].types.iter()) { for v in &a.0[0].types {
let v = v.as_any().downcast_ref::<data::int::IntT>().ok_or_else(|| CheckError::from(format!("expected int as first argument, but got {}", v.with_info(i))))?; let v = v.as_any().downcast_ref::<data::int::IntT>().ok_or_else(|| CheckError::from(format!("expected int as first argument, but got {}", v.with_info(i))))?;
if min.is_none_or(|min| min > v.0) { if min.is_none_or(|min| min > v.0) {
min = Some(v.0); min = Some(v.0);
} }
}
for v in &a.0[1].types {
let v = v.as_any().downcast_ref::<data::int::IntT>().ok_or_else(|| CheckError::from(format!("expected int as second argument, but got {}", v.with_info(i))))?;
if max.is_none_or(|max| max < v.1) { if max.is_none_or(|max| max < v.1) {
max = Some(v.1); max = Some(v.1);
} }
@ -84,11 +87,14 @@ impl Config {
if a.0.len() == 2 { if a.0.len() == 2 {
let mut min = None; let mut min = None;
let mut max = None; let mut max = None;
for v in a.0[0].types.iter().chain(a.0[1].types.iter()) { for v in &a.0[0].types {
let v = v.as_any().downcast_ref::<data::int::IntT>().ok_or_else(|| CheckError::from(format!("expected int as first argument, but got {}", v.with_info(i))))?; let v = v.as_any().downcast_ref::<data::int::IntT>().ok_or_else(|| CheckError::from(format!("expected int as first argument, but got {}", v.with_info(i))))?;
if min.is_none_or(|min| min > v.0) { if min.is_none_or(|min| min > v.0) {
min = Some(v.0); min = Some(v.0);
} }
}
for v in &a.0[1].types {
let v = v.as_any().downcast_ref::<data::int::IntT>().ok_or_else(|| CheckError::from(format!("expected int as second argument, but got {}", v.with_info(i))))?;
if max.is_none_or(|max| max < v.1) { if max.is_none_or(|max| max < v.1) {
max = Some(v.1); max = Some(v.1);
} }
@ -97,7 +103,7 @@ impl Config {
if let Some(max) = max.checked_sub(1) { if let Some(max) = max.checked_sub(1) {
o.add(Arc::new(RangeT(min, max))); o.add(Arc::new(RangeT(min, max)));
} else { } else {
o.add(Arc::new(RangeT(min.saturating_add(1), max))); o.add(Arc::new(RangeT(if min == isize::MIN { min + 1 } else { min }, isize::MIN)));
} }
} }
} else { } else {