GNOME Bugzilla – Bug 789443
Detect already implement interfaces in parent classes
Last modified: 2018-02-21 12:02:22 UTC
If you have: interface A : Object class B : Object, A And then create a new class as: class C : B, A This makes can produce a fail at runtime. While C code seems to be Ok, in GXml I have an infinite repetitive method call (I never find where in C code) executed at construction time. So if Vala's compiler founds a parent class already implement an interface, should rise an error on trying to reimplement it. Correct code should be: class C : B Now C is an object of type B and A also.
This is a code producing a Segmentation Fault, but correctly compiles: public interface Bar : Object { public abstract string name { get; set; } public abstract string get_text (); } public class BarC : Object, Bar { public string name { get; set; } public string get_text () { return "BarC"; } } public class BarD : BarC, Bar { public new string get_text () { return "BarD"; } } public void main () { var c = new BarD (); c.name = "D Class"; stdout.printf (c.name+"\n"); stdout.printf ((c as BarC).name+"\n"); stdout.printf ((c as Bar).name+"\n"); stdout.printf (c.get_text ()+"\n"); stdout.printf ((c as BarC).get_text ()+"\n"); stdout.printf ((c as Bar).get_text ()+"\n"); }
Code at Comment #1, produce at runtime a infinite call to property name.
By removing interface declaration at class BarD to have: public class BarD : BarC { public new string get_text () { return "BarD"; } } The program compiles an run with following results: D Class D Class D Class BarD BarC BarC But now you can see method Bar.get_text() is not overrided by BarD, so when using Bar interface to access a BarD object you will be using BarC implementation. So no way to override Bar.get_text() from BarD. By using following syntax: public new string Bar.get_text () { return "BarD"; } Should be possible to override BarC.get_text() implementation with the one provided by BarD.
*** This bug has been marked as a duplicate of bug 648897 ***