Skip to content

Commit

Permalink
can't unarray a scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 26, 2024
1 parent 0fa666a commit a3712fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
36 changes: 21 additions & 15 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,28 @@ impl Uiua {
unbox,
} => self.with_span(span, |env| {
let arr = env.pop(1)?;
if arr.row_count() != count {
if arr.row_count() != count || arr.shape() == [] {
let prim_text;
return Err(env.error(format!(
"This °{} expects an array with {} rows, \
but the array has {}",
if let Some(prim) = prim {
prim_text = prim.to_string();
prim_text.as_str()
} else if unbox {
"{}"
} else {
"[]"
},
count,
arr.row_count()
)));
let prim_text = if let Some(prim) = prim {
prim_text = prim.to_string();
prim_text.as_str()
} else if unbox {
"{}"
} else {
"[]"
};
return Err(env.error(if arr.shape() == [] {
format!(
"This °{prim_text} expects an array with {count} rows, \
but the array is a scalar"
)
} else {
format!(
"This °{prim_text} expects an array with {count} rows, \
but the array has {}",
arr.row_count()
)
}));
}
if unbox {
for val in arr.into_rows().rev() {
Expand Down
6 changes: 5 additions & 1 deletion tests/error.ua
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ comptime(⍤@@@@)
F! ← ^2

⬚0⌝⊏ ¯2 5
⬚0⌝⊡ ¯2 5
⬚0⌝⊡ ¯2 5

°¤ 1

°[∘] 1

0 comments on commit a3712fc

Please sign in to comment.