diff --git a/src/builtins/select.c b/src/builtins/select.c index f8b8e536..e1540be2 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -195,24 +195,24 @@ B select_c2(B t, B w, B x) { #define CASE(S, E) case S: for (usz i=i0; i= 4) { \ + if (sizeof(W) >= 4) { \ switch(xl) { default:UD; CASEW(3,u8); CASEW(4,u16); CASEW(5,u32); CASEW(6,u64); } \ - } else { \ - W* wt = NULL; \ + } else { \ + W* wt = NULL; \ for (usz bl=(1<<14)/sizeof(W), i0=0, i1=0; i0wia) i1=wia; \ + i1+=bl; if (i1>wia) i1=wia; \ W min=wp[i0], max=min; for (usz i=i0+1; imax) max=e; if (e=(i64)xn) thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", max, xn); \ - W* ip=wp; usz off=xn; \ - if (max>=0) { off=0; if (RARE(min<0)) { \ + if (min<-(i64)xn) select_properError(w, x); \ + if (max>=(i64)xn) select_properError(w, x); \ + W* ip=wp; usz off=xn; \ + if (max>=0) { off=0; if (RARE(min<0)) { \ if (RARE(xn > (1ULL<<(sizeof(W)*8-1)))) { w=taga(NEXT(w)); mm_free((Value*)r); return C2(select, w, x); } \ - if (!wt) {wt=TALLOCP(W,i1-i0);} ip=wt-i0;\ + if (!wt) {wt=TALLOCP(W,i1-i0);} ip=wt-i0; \ for (usz i=i0; i> (n%8)) & 1); \ if (i%64 == 0) { rp[i/64]=b; if (!i) break; } \ } \ diff --git a/test/cases/prims.bqn b/test/cases/prims.bqn index e98c88bb..fbeb2482 100644 --- a/test/cases/prims.bqn +++ b/test/cases/prims.bqn @@ -120,6 +120,10 @@ !"Expected integer, got 1.1" % %USE evar ⋄ 0‿1.1‿2 ⊏_evar ↕10 !"⊏: Indexing out-of-bounds (1∊𝕨, 1≡≠𝕩)" % %USE evar ⋄ 0‿0‿1 ⊏_evar 1‿3⥊↕10000 !"⊏: Indexing out-of-bounds (2∊𝕨, 2≡≠𝕩)" % %USE evar ⋄ (1+9=↕10) ⊏_evar ⟨1‿2,3⟩ +!"⊏: Indexing out-of-bounds (4∊𝕨, 3≡≠𝕩)" % %USE evar ⋄ 1‿4‿2‿0‿10‿5‿6 ⊏_evar 1‿0‿1 +!"⊏: Indexing out-of-bounds (¯4∊𝕨, 3≡≠𝕩)" % %USE evar ⋄ (-1‿4‿2‿0‿10‿5‿6) ⊏_evar 1‿0‿1 +!"⊏: Indexing out-of-bounds (4000∊𝕨, 1001≡≠𝕩)" % %USE evar ⋄ ( 1000×1‿4‿2‿0‿10‿5‿6) ⊏_evar 1001⥊1‿0‿1 +!"⊏: Indexing out-of-bounds (¯4000∊𝕨, 1001≡≠𝕩)" % %USE evar ⋄ (¯1000×1‿4‿2‿0‿10‿5‿6) ⊏_evar 1001⥊1‿0‿1 %USE tvar ⋄ !∘≡¨⟜⊏ ∾ {⥊𝕨 ⊏⎊(•CurrentError∘⊢) _tvar 𝕩}´¨ ⟨⟨0‿1, ⋈0⟩ ⋄ ⟨0‿1, "?"⟩ ⋄ ⟨0‿1, ≍0‿1⟩⟩ a←↕2 ⋄ ! "e" ≡ (↕10){b←a‿a‿a‿a‿a‿a‿a‿a‿a‿a ⋄ 𝕨⊏⎊"e"𝕩}⟨1‿2,3‿4⟩ ⋄ ! 0‿1 ≡ a %USE eqvar ⋄ {1‿¯1 {r←𝕨⊏𝕩 ⋄ ! 𝕩 ≥○•internal.ElType r ⋄ r}_eqvar 𝕩}¨ ⟨↕2, ↕4, "hello", ⟨"ab", "cd", "ef"⟩, ↕⋈4⟩