From 1ecc6b3918f4d2e350e0c55637a3b51fa0ae8f99 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 5 May 2025 18:57:31 +0300 Subject: [PATCH] =?UTF-8?q?more=20proper=20error=20message=20for=201?= =?UTF-8?q?=E2=8C=BE((<=E2=8B=880)=E2=8A=B8=E2=8A=91)=E2=86=955?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sfns.c | 4 +++- test/cases/prims.bqn | 2 ++ test/cases/under.bqn | 11 +++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 26237733..bf841de7 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -1400,7 +1400,9 @@ B pick_ucw(B t, B o, B w, B x) { } w = num_squeeze(mut_fcd(r, w)); B rep = isArr(o)? incG(o) : c1(o, C2(select, incG(w), C1(shape, incG(x)))); - if (isAtm(rep) || !eqShape(w, rep)) thrF("𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected %H, got %H)", w, rep); + // error messages will need to get more non-trivial for deeper mismatches + if (isAtm(rep)) thrM("𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)"); + if (!eqShape(w, rep)) thrF("𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected %H, got %H)", w, rep); return select_replace(U'⊑', w, x, rep, wia, xia, 1); } decG(w); diff --git a/test/cases/prims.bqn b/test/cases/prims.bqn index 4ca8a85b..1676e651 100644 --- a/test/cases/prims.bqn +++ b/test/cases/prims.bqn @@ -174,6 +174,8 @@ a←↕2 ⋄ ! "e" ≡ (↕10){b←a‿a‿a‿a‿a‿a‿a‿a‿a‿a ⋄ !"𝕨⊑𝕩: 𝕨 contained a non-integer" % ⟨0.1⟩⊑↕3 !"𝕨⊑𝕩: 𝕨 contained a non-integer" % ⟨2⋆80⟩⊑↕3 !"𝕨⊑𝕩: Leaf arrays in 𝕨 must have rank 1 (element: (1‿2⥊1‿2))" % %USE evar ⋄ (≍1‿2) {⟨𝕨⟩⊑𝕩}_evar ↕5‿5 +!"𝕨⊑𝕩: Leaf arrays in 𝕨 must have rank 1 (element: (<2))" % (<2)⊑↕3 +!"𝕨⊑𝕩: Leaf arrays in 𝕨 must have rank 1 (element: (<1))" % (<1)⊑"foo"‿"bar"‿"baz" %USE eqvar ⋄ 1‿2 ⊑_eqvar ↕5‿5 %% 1‿2 # >𝕩 diff --git a/test/cases/under.bqn b/test/cases/under.bqn index fc5c428e..c7f4af42 100644 --- a/test/cases/under.bqn +++ b/test/cases/under.bqn @@ -30,8 +30,15 @@ # ⊑ !"𝔽⌾(a⊸⊑): Incompatible result elements" % 10‿20⌾(⟨1‿2,1‿2⟩⊸⊑) 4‿5⥊↕9 -!"𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 10‿20‿30⌾(⟨1‿2,2‿1⟩⊸⊑) 4‿4⥊↕16 -!"𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 1⊸∾⌾(⟨1‿2,2‿1⟩⊸⊑) 4‿4⥊↕16 +!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 10‿20‿30⌾(⟨1‿2,2‿1⟩⊸⊑) 4‿4⥊↕16 +!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1⌾((<⋈2)⊸⊑) ↕10 +!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1⌾((<1‿2)⊸⊑) 3‿3⥊↕9 +!"⁼: Inverse not found" % 1⌾((<⋈⋈2)⊸⊑) ↕10 +!"⁼: Inverse not found" % 1⌾((<⋈1‿2)⊸⊑) 3‿3⥊↕9 +!"⁼: Inverse not found" % (<1)⌾((<⟨1‿2,2‿1⟩)⊸⊑) 3‿3⥊↕9 +!"⁼: Inverse not found" % 3‿4⌾((<⟨1‿2,2‿1⟩)⊸⊑) 3‿3⥊↕9 +!"𝕨⊑𝕩: Leaf arrays in 𝕨 must have rank 1 (element: (<2))" % 1⌾((<2)⊸⊑) ↕10 +!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 1⊸∾⌾(⟨1‿2,2‿1⟩⊸⊑) 4‿4⥊↕16 !"𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡¯10, 3≡≠𝕩)" % 1⊸+⌾(¯10⊸⊑) ↕3 !"𝕨⊑𝕩: 𝕨 contained list with mixed-type elements" % 'a'⌾(1‿'a'⊸⊑) 4‿5⥊↕9 !"𝕨⊑𝕩: Indexing out-of-bounds (index 1‿5 in array of shape 4‿5)" % 'a'⌾(1‿5⊸⊑) 4‿5⥊↕9