Better error messages for unknown namespace key
This commit is contained in:
parent
0b6c5189d8
commit
8e35241e47
20
src/ns.c
20
src/ns.c
@ -3,10 +3,10 @@
|
||||
#include "vm.h"
|
||||
|
||||
void m_nsDesc(Body* body, bool imm, u8 ty, i32 actualVam, B nameList, B varIDs, B exported) { // doesn't consume nameList
|
||||
if (!isArr(varIDs) || !isArr(exported)) thrM("Bad namespace description information");
|
||||
if (!isArr(varIDs) || !isArr(exported)) thrM("Internal error: Bad namespace description information");
|
||||
|
||||
usz ia = IA(varIDs);
|
||||
if (ia!=IA(exported)) thrM("Bad namespace description information");
|
||||
if (ia!=IA(exported)) thrM("Internal error: Bad namespace description information");
|
||||
i32 off = (ty==0?0:ty==1?2:3) + (imm?0:3);
|
||||
i32 vam = ia+off;
|
||||
|
||||
@ -37,6 +37,12 @@ B m_ns(Scope* sc, NSDesc* desc) { // consumes both
|
||||
}
|
||||
|
||||
|
||||
NORETURN NOINLINE static void ns_unk_B(B x) {
|
||||
thrF("Field named %B not found", x);
|
||||
}
|
||||
NORETURN NOINLINE static void ns_unk_gid(i32 gid) {
|
||||
ns_unk_B(gid2str(gid));
|
||||
}
|
||||
|
||||
B ns_getU(B ns, i32 gid) { VTY(ns, t_ns);
|
||||
NS* n = c(NS, ns);
|
||||
@ -44,7 +50,7 @@ B ns_getU(B ns, i32 gid) { VTY(ns, t_ns);
|
||||
|
||||
i32 ia = d->varAm;
|
||||
for (i32 i = 0; i < ia; i++) if (d->expGIDs[i]==gid) return n->sc->vars[i];
|
||||
thrM("No key found");
|
||||
ns_unk_gid(gid);
|
||||
}
|
||||
|
||||
B ns_qgetU(B ns, i32 gid) { VTY(ns, t_ns);
|
||||
@ -64,7 +70,7 @@ B ns_getNU(B ns, B name, bool thrEmpty) { VTY(ns, t_ns);
|
||||
i32 ia = d->varAm;
|
||||
for (i32 i = 0; i < ia; i++) if (d->expGIDs[i]==gid) return n->sc->vars[i];
|
||||
}
|
||||
if (thrEmpty) thrF("No field named %B found", name);
|
||||
if (thrEmpty) ns_unk_B(name);
|
||||
return bi_N;
|
||||
}
|
||||
B ns_getC(B ns, char* name) {
|
||||
@ -88,7 +94,7 @@ void ns_set(B ns, B name, B val) { VTY(ns, t_ns);
|
||||
return;
|
||||
}
|
||||
}
|
||||
thrM("No key found");
|
||||
ns_unk_B(name);
|
||||
}
|
||||
|
||||
|
||||
@ -159,7 +165,7 @@ i32 nns_pos(Body* body, B name) {
|
||||
i32 pos = body->varData[i+ia];
|
||||
if (pos>=0 && equal(name, GetU(nameList, pos))) { dec(name); return i; }
|
||||
}
|
||||
thrM("No key found");
|
||||
ns_unk_B(name);
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +175,7 @@ i32 pos2gid(Body* body, i32 pos) {
|
||||
if (LIKELY(gid!=-1)) return gid;
|
||||
|
||||
i32 nlIdx = body->varData[pos+body->varAm];
|
||||
if (nlIdx==-1) thrM("Cannot use special variable name as namespace key");
|
||||
if (nlIdx==-1) thrM("Internal error: Cannot use special variable name as namespace key");
|
||||
return body->varData[pos] = str2gid(IGetU(body->bl->comp->nameList, nlIdx));
|
||||
}
|
||||
|
||||
|
||||
@ -49,9 +49,11 @@ a←↕2 ⋄ a {𝕊: a←"foo" ⋄ {𝕊:a!↩0}⎊•CurrentError @}↩ ⋄ %
|
||||
|
||||
# namespaces
|
||||
⟨a,b⟩←•BQN"{x⇐1‿2⋄a⇐3‿4⋄y←5‿6⋄b⇐7‿8}" ⋄ a‿b %% ⟨3‿4 ⋄ 7‿8⟩
|
||||
!"Field named ""b"" not found" % {a⇐1}.b
|
||||
!"Field named ""y"" not found" % x‿y‿z ← {x‿z⇐1‿2}
|
||||
|
||||
# immediate modifiers
|
||||
!"No key found" % X←1‿2{a⇐𝕗} ⋄ ⟨b⟩←x
|
||||
!"Field named ""b"" not found" % X←1‿2{a⇐𝕗} ⋄ ⟨b⟩←x
|
||||
X←1‿2{a⇐𝕗} ⋄ ⟨a⟩←x ⋄ +´a %% 3
|
||||
X←1‿2{a⇐𝕘-𝕗}3‿4 ⋄ ⟨a⟩←x ⋄ +´a %% 4
|
||||
⟨a⟩←1‿2{a⇐𝕩+𝕗+𝕘}3‿4 1 ⋄ a %% 5‿7
|
||||
|
||||
@ -49,7 +49,7 @@ f ← •ReBQN{repl⇐"none"} ⋄ !6≡•Type F "⇐"
|
||||
|
||||
# •ns
|
||||
{abc⇐1 ⋄ dÊF⇐2}•ns.Get¨ ⟨"abc", "ABC", "abC", "abc___", "DêF", "__D__Ê__F__"⟩ %% 1‿1‿1‿1‿2‿2
|
||||
!"No field named ""abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþabcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ𝕨𝕨⍉!0123456789"" found" % {abc⇐1 ⋄ dÊF⇐2}⊸•ns.Get "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞabcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ𝕨𝕨⍉!0123456789_"
|
||||
!"Field named ""abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþabcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ𝕨𝕨⍉!0123456789"" not found" % {abc⇐1 ⋄ dÊF⇐2}⊸•ns.Get "ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞabcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ𝕨𝕨⍉!0123456789_"
|
||||
{abc⇐1 ⋄ dÊF⇐2 ⋄ n10⇐3}•ns.Has¨ ⟨"abc", "ABC", "abC", "abc___", "DêF", "__D__Ê__F__", "àbc", "def", "", ↕0, "𝕨", "012", "n10", "n1_0"⟩ %% 1‿1‿1‿1‿1‿1‿0‿0‿0‿0‿0‿0‿1‿1
|
||||
∨´{⇐}•ns.Has¨↑"abc123AEWQE___àÀ𝕨𝕩" %% 0
|
||||
!"•ns.Has: 𝕩 must be a string" % {⇐}•ns.Has ≍""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user