From 3d3e7f0bbcfa3dee4baaae67a18edfa6d62def08 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 5 Jul 2017 22:26:52 -0700 Subject: structs: get tests/012/stslot.tl to pass. * struct.c (static_slot_rewrite_rec): A simple rearrangement: switch to postorder traversal, doing the derived structs first, then this struct. Why does this fix a bug? Because when the assignment *s = *to occurs for the node at the root of the recursion, s and from point to the same object. And so the assignment alters from, which is the search key. When the children are then processed, the search key doesn't match anything: it now looks like the to slot that the children are supposed to get, and so they don't have it, of course. So in other words the slot being rewritten is not found in the derived types and not rewritten there as it should be. --- struct.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/struct.c b/struct.c index 6d72d2ae..2fc114c1 100644 --- a/struct.c +++ b/struct.c @@ -1024,6 +1024,13 @@ static void static_slot_rewrite_rec(struct struct_type *st, struct stslot *to) { cnum i; + val iter; + + for (iter = st->dvtypes; iter; iter = cdr(iter)) { + val stype = car(iter); + struct struct_type *st = coerce(struct struct_type *, stype->co.handle); + static_slot_rewrite_rec(st, from, to); + } for (i = 0; i < st->nstslots; i++) { struct stslot *s = &st->stslot[i]; @@ -1035,16 +1042,6 @@ static void static_slot_rewrite_rec(struct struct_type *st, *s = *to; } } - - { - val iter; - - for (iter = st->dvtypes; iter; iter = cdr(iter)) { - val stype = car(iter); - struct struct_type *st = coerce(struct struct_type *, stype->co.handle); - static_slot_rewrite_rec(st, from, to); - } - } } -- cgit v1.2.3