After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 789443 - Detect already implement interfaces in parent classes
Detect already implement interfaces in parent classes
Status: RESOLVED DUPLICATE of bug 648897
Product: vala
Classification: Core
Component: Code Generator: GObject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2017-10-24 22:28 UTC by Daniel Espinosa
Modified: 2018-02-21 12:02 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daniel Espinosa 2017-10-24 22:28:16 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.
Comment 1 Daniel Espinosa 2017-10-24 22:40:59 UTC
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");
}
Comment 2 Daniel Espinosa 2017-10-24 22:43:07 UTC
Code at Comment #1, produce at runtime a infinite call to property name.
Comment 3 Daniel Espinosa 2017-10-24 22:48:37 UTC
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.
Comment 4 Rico Tzschichholz 2018-02-21 12:02:22 UTC

*** This bug has been marked as a duplicate of bug 648897 ***