[Vala] GLib List.append sometimes fails when called from a different class



When SomeClass appends items to the list, FailDemo doesn't notice, and
thinks that the list is still empty. Interestingly, this problem only
happens when the list is empty: if I append some items in the FailDemo
constructor *first*, then FailDemo does notice subsequent items appended by
SomeClass.

Is this a bug?

----------

public class FailDemo : GLib.Object
{
  public List<int?> some_list = new List<int?>();

  public FailDemo()
  {
    SomeClass sc = new SomeClass(some_list);
  }
}

public class SomeClass : GLib.Object
{
  public SomeClass(List<int?> some_list)
  {
    some_list.append(1);
    some_list.append(2);
    some_list.append(3);

    stdout.printf("SomeClass successfully appended %u items\n",
some_list.length());
    // SomeClass successfully appended 3 items
  }
}

int main (string[] args)
{
  FailDemo fd = new FailDemo();

  stdout.printf("And yet FailDemo sees %u items in the list\n",
fd.some_list.length());
  // And yet FailDemo sees 0 items in the list

  return 0;
}


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