Re: [Vala] I'm missing Java's anonymous classes



Nor Jaidi Tuah wrote:
This seems okay so far, but here comes the killer:

  public class Display : Widget {
     public Display() {
        base(relayout_imp);
     }
     private void relayout_imp() { ... }
  }

This crashes when relayout() is called because the 'relayout_imp'
argument to the constructor needs 'self' but 'self' hasn't been
initialised yet (so is NULL).

That must be a compiler error. If self is really NULL,
then even a direct call to a method from the constructor
won't work.

The compiled code is something like this (from memory):

   self = uazu_win_widget_construct(uazu_win_display_relayout_imp, self);

i.e. the delegate is a dual-pointer (func, target), with 'self' as the
second part.  But 'self' hasn't yet been initialised, because the
widget constructor call hasn't yet been made, so NULL is passed.

There is no way that the Vala compiler can make this work, as far as I
can see.  A delegate which depends on 'self' can never be passed to a
constructor.

Jim

-- 
 Jim Peters                  (_)/=\~/_(_)                 jim uazu net
                          (_)  /=\  ~/_  (_)
 UazĂș                  (_)    /=\    ~/_    (_)                http://
 in Peru            (_) ____ /=\ ____ ~/_ ____ (_)            uazu.net



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