diff --git a/multiply_add.sus b/multiply_add.sus index fe34f62..a40c004 100644 --- a/multiply_add.sus +++ b/multiply_add.sus @@ -303,7 +303,7 @@ module generative : int in -> int o, int o2 { o = a[in]; - o2 = a[a[1]]; + o2 = a[a[0]]; } diff --git a/src/instantiation/mod.rs b/src/instantiation/mod.rs index e102dc7..dfd3735 100644 --- a/src/instantiation/mod.rs +++ b/src/instantiation/mod.rs @@ -167,7 +167,7 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> { match IntT::try_from(val) { Ok(val) => Some(val), Err(e) => { - self.errors.error_basic(span, format!("Generative integer too large: {val}")); + self.errors.error_basic(span, format!("Generative integer does not fit in {}: {val}", std::any::type_name::())); None } } @@ -302,7 +302,12 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> { let Value::Array(arr_val) = self.get_generation_value(arr)? else {return None}; let arr_idx_val = self.get_generation_value(arr_idx)?; let idx : usize = self.extract_integer_from_value(arr_idx_val, arr_idx.1)?; - arr_val[idx].clone() + if let Some(item) = arr_val.get(idx) { + item.clone() + } else { + self.errors.error_basic(arr_idx.1, format!("Compile-Time Array index is out of range: idx: {idx}, array size: {}", arr_val.len())); + return None + } } WireSource::Constant{value} => value.clone() })