[Vala] Setting and getting properties at the same time



Hello list,

I stumbled on some (for me) unexpected behaviour when setting and getting a property at the same time, which is not consistend with simple types like int.

When doing something like

int x = (myclass.myproperty = y);

x will be set to y, and not whatever mycalss.myproperty will be (or what was mycalss.myproperty set to before). Is this a limitation of Vala?

The code below shows this behaviour and should be pretty self-explanatory.

---------- snip ----------

public class myclass : Object
{
   private int _number;

   public int number {
      set { _number = value * 2; }
      get { return _number; }
   }
}

public void main(string[] args)
{
   myclass m = new myclass();
   int i = 2;

   m.number = 2;

   // prints 4, ok
   stdout.printf("number: %d\n", m.number);

   // prints 3, not 6 (or at least 4)
   stdout.printf("number: %d\n", m.number = 3);

   // prints 6, ok
   stdout.printf("number: %d\n", m.number);

   / prints 5, ok
   stdout.printf("i: %d\n", i = 5);
}

---------- snip ----------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]