I think that it is pretty consistent and expected behaviour not only in
Vala but in other languages as well (as long as they allow such things). I
would be worried if it would work other way around. Example:

int x, y;
x = 2;
y = x = 3;

I expect that both y and x will have same value, 3. I would not like to get
y=2 and x=3.

I hope that this clears things up but I also wonder in which language it
works differently.

JC

2012/11/1 foracc <for...@d00m.info>

> 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 ----------
> ______________________________**_________________
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/**mailman/listinfo/vala-list<https://mail.gnome.org/mailman/listinfo/vala-list>
>
_______________________________________________
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to