[Vala] abstract property without set accessor
- From: Thomas Jollans <t jollybox de>
- To: vala-list gnome org
- Subject: [Vala] abstract property without set accessor
- Date: Sat, 01 Sep 2012 14:14:10 +0200
Hi,
I'm a bit surprised by Vala's handling of abstract properties. When I
declare an abstract property with just the get accessor, like so:
public interface WithProperty : Object
{
public abstract string myprop { get; }
}
- I'd assume this to mean: the implementing class must have a property
"myprop", and this must have a public get accessor. In effect, I'd
assume the property declaration to be identical to the following, just
with the property syntax enabled:
public abstract string get_myprop ();
The interface doesn't care whether the property is publicly writeable.
It doesn't care whether it's constructed in the GObject fashion or the
C# fashion. It really just cares that the property can be read. I would
expect the two implementations to be possible:
public class ImplementsPropertyAutomatic : Object, WithProperty
{
public string myprop { get; construct; }
public ImplementsPropertyAutomatic ()
{
Object ( myprop : "foo" );
}
}
public class ImplementsPropertyManual : Object, WithProperty
{
public string myprop {
get {
return "bar";
}
}
public ImplementsPropertyManual ()
{
}
}
However, the vala compiler thinks differently. Apparently, a lack of
accessor in the abstract property declaration constitutes a ban on that
accessor:
proptest.vala:8.5-8.24: error: Type and/or accessors of overriding
property `ImplementsPropertyAutomatic.myprop' do not match overridden
property `WithProperty.myprop': incompatible set accessor.
public string myprop { get; construct; }
^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
What is the reasoning behind this? It appears inconsistent with the
general behaviour of interfaces and abstract classes, that specify the
minimum capabilities of the implementor, not the exact capabilities. Is
the behaviour I'm expecting simply not possible with GObject? Or could
this be considered a bug in Vala?
Or am I missing some syntactical sugar that eliminates the problem?
Regards
Thomas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]