diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-05-29 06:47:55 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-05-29 06:47:55 -0700 |
commit | c1f37292a3f48e2d7c641e9df8160967002d8c6e (patch) | |
tree | deb0c6977cdbbadcd0863f72fa385e39a42bc1f6 /struct.c | |
parent | 9523628e5ef65c70aad5b8b49606b37fc9a34404 (diff) | |
download | txr-c1f37292a3f48e2d7c641e9df8160967002d8c6e.tar.gz txr-c1f37292a3f48e2d7c641e9df8160967002d8c6e.tar.bz2 txr-c1f37292a3f48e2d7c641e9df8160967002d8c6e.zip |
structs: slot access on non-struct: improve diagnosis.
* struct.c (struct_handle_for_slot): New static function.
(slot, maybe_slot, slotset): Use struct_handle_for_slot rather
than struct_handle, for improved error message that reveals
what slot name was requested.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -660,6 +660,14 @@ static struct struct_inst *struct_handle(val obj, val ctx) ctx, obj, nao); } +static struct struct_inst *struct_handle_for_slot(val obj, val ctx, val slot) +{ + if (cobjp(obj) && obj->co.ops == &struct_inst_ops) + return coerce(struct struct_inst *, obj->co.handle); + uw_throwf(error_s, lit("~a: attempt to access slot ~s of non-structure ~s"), + ctx, slot, obj, nao); +} + val copy_struct(val strct) { const val self = lit("copy-struct"); @@ -949,7 +957,7 @@ static noreturn void no_such_static_slot(val ctx, val type, val slot) val slot(val strct, val sym) { const val self = lit("slot"); - struct struct_inst *si = struct_handle(strct, self); + struct struct_inst *si = struct_handle_for_slot(strct, self, sym); if (sym && symbolp(sym)) { loc ptr = lookup_slot_load(strct, si, sym); @@ -963,7 +971,7 @@ val slot(val strct, val sym) val maybe_slot(val strct, val sym) { const val self = lit("slot"); - struct struct_inst *si = struct_handle(strct, self); + struct struct_inst *si = struct_handle_for_slot(strct, self, sym); if (sym && symbolp(sym)) { loc ptr = lookup_slot_load(strct, si, sym); @@ -977,7 +985,7 @@ val maybe_slot(val strct, val sym) val slotset(val strct, val sym, val newval) { const val self = lit("slotset"); - struct struct_inst *si = struct_handle(strct, self); + struct struct_inst *si = struct_handle_for_slot(strct, self, sym); if (sym && symbolp(sym)) { loc ptr = lookup_slot(strct, si, sym); |