Skip to content

Commit b56e0de

Browse files
test inheritance
1 parent 3e1096a commit b56e0de

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

pickle.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,22 @@ object* pvm::get_property(object* obj, uint64_t hash, bool recurse) {
526526
// Nil has no properties
527527
if (!obj) return nil;
528528
if (recurse) {
529+
DBG("Inheritance requested get_property() {");
529530
// Try to find it directly.
530531
object* val = this->get_property(obj, hash, false);
531-
if (val) return val;
532+
if (val) {
533+
DBG("Own property. }");
534+
return val;
535+
}
532536
// Not found, traverse prototypes list.
533537
for (object* p = car(obj); p; p = cdr(p)) {
534538
val = this->get_property(car(p), hash, true);
535-
if (val) return val;
539+
if (val) {
540+
DBG("Parent property. }");
541+
return val;
542+
}
536543
}
544+
DBG("Property not found in inheritance tree. }");
537545
return nil;
538546
}
539547
// Check if it is an object-object (primitives have no own properties)

pickle_test.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ int main() {
107107
vm.dump(hash0);
108108
putchar('\n');
109109
vm.dump(foo);
110+
printf("\nCreate child object\n");
111+
auto bar = vm.newobject(vm.cons(foo, nil));
112+
vm.dump(bar);
113+
printf("\nGet property 0 with inheritance and without\n");
114+
ASSERT(vm.get_property(bar, 0, false) == nil);
115+
ASSERT(vm.get_property(bar, 0, true) != nil);
110116
SEPARATOR;
111117
printf("all done -- cleaning up\n");
112118
// implicit destruction of vm;

test/out32.txt

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/out64.txt

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/valgrind32.txt

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/valgrind64.txt

+13-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)