diff --git a/src/modules/expression/binop/range.rs b/src/modules/expression/binop/range.rs index 68481e05..7120a4ff 100644 --- a/src/modules/expression/binop/range.rs +++ b/src/modules/expression/binop/range.rs @@ -1,11 +1,13 @@ +use std::ops::Sub; use heraclitus_compiler::prelude::*; use crate::docs::module::DocumentationModule; -use crate::{handle_binop, error_type_match}; -use crate::modules::{expression::expr::Expr, types::{Type, Typed}}; +use crate::modules::expression::expr::{Expr, ExprType}; +use crate::modules::types::{Type, Typed}; use crate::utils::metadata::ParserMetadata; use crate::translate::compute::{translate_computation, ArithOp}; use crate::translate::module::TranslateModule; use crate::utils::TranslateMetadata; +use crate::{handle_binop, error_type_match}; use super::BinOp; #[derive(Debug, Clone)] @@ -59,7 +61,11 @@ impl TranslateModule for Range { let from = self.from.translate(meta); let to = self.to.translate(meta); if self.neq { - let to_neq = translate_computation(meta, ArithOp::Sub, Some(to), Some("1".to_string())); + let to_neq = if let Some(ExprType::Number(_)) = &self.to.value { + to.parse::().unwrap_or_default().sub(1).to_string() + } else { + translate_computation(meta, ArithOp::Sub, Some(to), Some("1".to_string())) + }; meta.gen_subprocess(&format!("seq {} {}", from, to_neq)) } else { meta.gen_subprocess(&format!("seq {} {}", from, to))