[EDIT: Note that the title of the post was modified to reflect that fact that on some interpreters the error generated is serious (causing interpreter halt) instead of an RTE. See follow-up posts below for details.]
The following code causes some unexpected RTEs (run-time errors) that don’t seem to make sense:
[ InitializeParentClasses o c;
objectloop (o ofclass Ext_Class) ! should ensure only objects with parent_class property are found
{
objectloop (c ofclass Class && c ~= Class or Object or Routine or String or Ext_Class)
{
print "Setting ", (name) o, ".parent_class to ", (name) c, ".^";
o.parent_class = c; ! why does this cause an RTE "no property parent_class to set"?
}
}
];
! This is apparently the wrong location for the Ext_Class definition, move ahead of InitializeParentClasses to fix
Class Ext_Class
with parent_class;
Class Pebble(5)
class Ext_Class
with short_name "tiny pebble";
Object Pail; ! this will not get a parent_class and be skipped by InitializeParentClasses()
[ Main ;
InitializeParentClasses();
SeeAllPebbles();
new_line;
];
[ SeeAllPebbles x ;
objectloop (x ofclass Pebble)
{
print "Object ", (name) x, " is a child of ", (name) parent(x);
if (x ofclass Pebble)
print " and has parent_class ", (name) x.parent_class;
print "^";
}
];
The specific error messages produced are:
Setting Pebble_1.parent_class to class Pebble.
[** Programming error: Pebble_1 (object number 7) has no property parent_class to set **]
Setting Pebble_2.parent_class to class Pebble.
[** Programming error: Pebble_2 (object number 8) has no property parent_class to set **]
Setting Pebble_3.parent_class to class Pebble.
[** Programming error: Pebble_3 (object number 9) has no property parent_class to set **]
Setting Pebble_4.parent_class to class Pebble.
[** Programming error: Pebble_4 (object number 10) has no property parent_class to set **]
Setting Pebble_5.parent_class to class Pebble.
[** Programming error: Pebble_5 (object number 11) has no property parent_class to set **]
Setting Pebble_6.parent_class to class Pebble.
[** Programming error: Pebble_6 (object number 12) has no property parent_class to set **]
Object Pebble_1 is a child of class Pebble and has parent_class nothing
Object Pebble_2 is a child of class Pebble and has parent_class nothing
Object Pebble_3 is a child of class Pebble and has parent_class nothing
Object Pebble_4 is a child of class Pebble and has parent_class nothing
Object Pebble_5 is a child of class Pebble and has parent_class nothing
Object Pebble_6 is a child of class Pebble and has parent_class nothing
[Hit any key to exit.]
As noted in the source code’s comments, the cause of the issue seems to be the relative order of the definitions for Ext_Class and InitializeParentClasses. If Ext_Class comes first, then the code works as expected:
Setting Pebble_1.parent_class to class Pebble.
Setting Pebble_2.parent_class to class Pebble.
Setting Pebble_3.parent_class to class Pebble.
Setting Pebble_4.parent_class to class Pebble.
Setting Pebble_5.parent_class to class Pebble.
Setting Pebble_6.parent_class to class Pebble.
Object Pebble_1 is a child of class Pebble and has parent_class class Pebble
Object Pebble_2 is a child of class Pebble and has parent_class class Pebble
Object Pebble_3 is a child of class Pebble and has parent_class class Pebble
Object Pebble_4 is a child of class Pebble and has parent_class class Pebble
Object Pebble_5 is a child of class Pebble and has parent_class class Pebble
Object Pebble_6 is a child of class Pebble and has parent_class class Pebble
[Hit any key to exit.]
Note that the compiler does not complain that property parent_class is not defined when Ext_Class is placed after InitializeParentClasses(). This makes me think that it is doing some sort of lookahead pass, which makes me think that it should be able to pick up the property in the later Ext_Class definition. Also note that it is possible to set the parent_class of a Pebble instance in Main even when InitializeParentClasses() is causing RTEs.
It seems like, at the very least, the RTE error message is inappropriate in this case, as the objects in question clearly do have the parent_class property.
Does this count as an I6 bug? If so, is it possible to report this anywhere right now? (I see that the Mantis bug reporting system is still down at inform7.com; does anyone know when/if it will be restored?)
(And yes, I recognize that multiple inheritance means that a given object can have more than one “parent” class, so it doesn’t necessarily make sense to store the information in a single variable.)