Overriding inherited interface vfuncs clobbers base class implementation
Submitted by Simon Feltman
Link to original bug (#735307)
Description
While trying to find a solution for bug 703338, I noticed gjs suffers the same problem (the code in question has a similar origin). The problem is most easily described as follows:
const MyEntry = new Lang.Class({
Name: 'MyEntry',
Extends: Gtk.Entry,
vfunc_changed: function(entry) {
log('changed!');
}
});
The problem with this is by adding vfunc_changed(), gjs (and pygi) will clobber the default vfunc implementation for Gtk.Entry's Editable interface, essentially applying the sub-class vfunc to all instances of Gtk.Entry. The workaround (or correct way to do this) is to add "Implements" (or in pygi sub-class from the interface):
const MyEntry = new Lang.Class({
Name: 'MyEntry',
Extends: Gtk.Entry,
Implements: [ Gtk.Editable ],
vfunc_changed: function(entry) {
log('changed!');
}
});
While this fixes the problem, I think the problematic example can lead to a really bad and hard to debug developer experience. We should probably detect this and issue an error noting the interface must be listed in Implements, or automatically re-add the interface to the new type being initialized (I think this would be preferred).
See also bug 730740 and bug 566571.