Skip to content

Commit 244afba

Browse files
committed
add shape checks for pervasive functions
1 parent 97b3220 commit 244afba

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/algorithm/pervade.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::{
77

88
use ecow::eco_vec;
99

10+
use crate::algorithm::validate_size;
1011
use crate::fill::FillValue;
1112
use crate::{algorithm::loops::flip, array::*, Uiua, UiuaError, UiuaResult, Value};
1213
use crate::{Complex, Shape};
@@ -145,7 +146,8 @@ where
145146

146147
// dbg!(&a.shape, &b.shape, &new_shape);
147148

148-
let mut new_data = eco_vec![C::default(); new_shape.elements()];
149+
let elem_count = validate_size::<C>(new_shape.iter().copied(), env)?;
150+
let mut new_data = eco_vec![C::default(); elem_count];
149151
if !new_shape.contains(&0) {
150152
let slice = new_data.make_mut();
151153
let a_fill = a_fill.as_ref().ok();
@@ -375,6 +377,7 @@ where
375377
};
376378
let (new_shape, requires_fill) =
377379
derive_new_shape(&a.shape, &b.shape, fill.as_ref().err().copied(), env)?;
380+
validate_size::<T>(new_shape.iter().copied(), env)?;
378381
let fill = if requires_fill { fill.ok() } else { None };
379382

380383
// dbg!(a.shape, b.shape, &new_shape, &fill);

tests_special/error.ua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,6 @@ F ← |0.1000 ⍢(F F F|1)
184184

185185
⊥1 5
186186

187-
|
187+
|
188+
189+
+⊸¤⇡1e5

0 commit comments

Comments
 (0)