Skip to content

Commit

Permalink
fix a crash in pervasive repeat and switch
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 26, 2024
1 parent 4daba71 commit 934fe4c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/algorithm/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn repeat(with_inverse: bool, env: &mut Uiua) -> UiuaResult {
Err(row) => row.clone(),
};
// println!("row: {:?}", row);
if n.rank() > row.rank() {
if n.rank() > row.rank() || is_empty {
rows_to_sel.push(Err(row));
} else {
let row_shape = row.shape()[n.rank()..].into();
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub fn switch(
Err(row) => row.clone(),
};
// println!("row: {:?}", row);
if selector.rank() > row.rank() {
if selector.rank() > row.rank() || is_empty {
rows_to_sel.push(Err(row));
} else {
let row_shape = row.shape()[selector.rank()..].into();
Expand Down
2 changes: 2 additions & 0 deletions tests/loops.ua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ A ← ↯2_3_4⇡24
⍤⟜≍: [+1.+1. 2_4_6] ⍥(+1) [+1.+1. 1_2_3] ¤[1 2 3]
⍤⟜≍: [..4_5_6] ⍥(+1) [+1.+1. 1_2_3] [1 2 3]
⍤⟜≍: 5 ⍥(+1) ¯5 10
⍤⟜≍: ↯0_3e ⍥∘[] ¤[1 2 3]
⍤⟜≍: ↯0_0e ⍥∘[] ¤[]

# Do
⍤⟜≍: 1024 ⍢(×2)(<1000) 1
Expand Down
2 changes: 2 additions & 0 deletions tests/units.ua
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ F ← ⨬(¯|+1|×10|∞)
⍤⟜≍: [¯5 6 50 ∞] F [0 1 2 3] 5
⍤⟜≍: [¯1_2_10_∞ ¯2_3_20_∞ ¯3_4_30_∞] F [..0_1_2_3] [1 2 3]
⍤⟜≍: [..¯5_6_50_∞] F [..0_1_2_3] 5
⍤⟜≍: ↯0_3e ⨬∘∘[] ¤[1 2 3]
⍤⟜≍: ↯0_0e ⨬∘∘[] ¤[]

# Where
⍤⟜≍: [0 3 5 6] ⊚[1 0 0 1 0 1 1 0]
Expand Down

0 comments on commit 934fe4c

Please sign in to comment.