Vala not considering methods generated by property
I lacked a better title for this issue report.
Basically, I'm trying to create a custom widget that implements Gtk.Editable
. The widget doesn't have to do much because the widget has a backing Gtk.Text
that provides all the editable functionality.
The Gtk.Editable
interface requires both a text
property and a get_text
method.
Here's some demo code to illustrate the issue:
class MyWidget : Gtk.Widget, Gtk.Editable {
private Gtk.Text text_widget;
public string text {
get { return text_widget.text; }
set { text_widget.text = value; }
}
}
Since the text
property generates a get_text
method, I'd assume that the vala compiler know that the method has been implemented, however, the above only code will fail with:
error: `MyWidget' does not implement interface method `Gtk.Editable.get_text'
which is a bit surprising and frankly wrong, since vala itself will autogenerate a method of the name get_text
.
However, more issues arise when you try to implement the method yourself:
class MyWidget : Gtk.Widget, Gtk.Editable {
private Gtk.Text text_widget;
public string text {
get { return text_widget.text; }
set { text_widget.text = value; }
}
public unowned string get_text () {
return this.text_widget.get_text ();
}
}
The vala compiler won't be happy:
error: internal: Redefinition of `my_widget_real_get_text'
And this makes the issue unfixable.
The issue will persist no matter how many [CCode (cname="my_widget_get_text2")]
attributes I add. I added them to the property, set
statement and even the method itself to no avail:
class MyWidget : Gtk.Widget, Gtk.Editable {
private Gtk.Text text_widget;
public string text {
[CCode (cname="my_widget_get_text_property")]
get { return text_widget.text; }
set { text_widget.text = value; }
}
[CCode (cname="my_widget_get_text_method")]
public unowned string get_text () {
return this.text_widget.get_text ();
}
}
error: internal: Redefinition of `my_widget_real_get_text'
Which makes me believe the checks are made before the CCode
attributes are considered.