Objects implementing an interface extending another object implementing such method might need manual method redifinitions
Not sure this is a gjs issue actually, but using something like this:
const GObject = imports.gi.GObject;
const AGObjectInterface = GObject.registerClass({
Requires: [ GObject.Object ],
}, class AGObjectInterface extends GObject.Interface {
ifaceMethod() {
throw new GObject.NotImplementedError();
}
});
var BaseGObject = GObject.registerClass(
class extends GObject.Object {
ifaceMethod() {
print("REQUIRED iface method implemented by base obj");
}
otherMethod() {
print("Other method in base obj");
}
});
const GObjectImplementingGObjectInterface = GObject.registerClass({
Implements: [ AGObjectInterface ],
}, class GObjectImplementingGObjectInterface extends BaseGObject {
// ifaceMethod() {
// super.ifaceMethod();
// }
});
var OtherObj = GObject.registerClass(
class OtherObj extends GObjectImplementingGObjectInterface {
ifaceMethod() {
print("REQUIRED method calling super implementation too");
super.ifaceMethod();
}
otherMethod() {
print("Other method calling super implementation too");
super.otherMethod();
}
});
let obj = new OtherObj();
obj.otherMethod();
obj.ifaceMethod();
Other method calling super implementation too
Other method in base obj
REQUIRED method calling super implementation too
(gjs:16453): Gjs-WARNING **: 04:36:04.593: JS ERROR: NotImplementedError
NotImplementedError@resource:///org/gnome/gjs/modules/overrides/GObject.js:830:19
ifaceMethod@/tmp/ifacebug.js:7:15
ifaceMethod@/tmp/ifacebug.js:33:9
@/tmp/ifacebug.js:44:1
Script /tmp/ifacebug.js threw an exception
Where BaseGObject
is a simple GObject that has a ifaceMethod
definition (but not implementing the iface per se, as let's say it's outside our project scope) that is extended by GObjectImplementingGObjectInterface
that is actually implementing the iface and extended again by OtherObj that has metod implementations...
Unless de-commenting the definition of GObjectImplementingGObjectInterface.ifaceMehtod()
, this throws a GObject.NotImplementedError
, as it seems that the iface method definition takes the priority.
A simple implementation that also show the same problem unless defining the requiredG
is here.
This is quite a corner case, and probably the fact that this manual operation has to be done is expected, but I wonder if instead there's some hidden bug and we'd expect in this case to have super.ifaceMethod();
to automatically chain-up to the defined one by the base obj.