[Vala] wrong code generated with thread function



Hello,

I'm using valac 0.7.7 and the following small example is compiled into erroneous C code:

        class BrokenThread
        {
            void *a_method()
            {
                while (true)
                {
                    Thread.usleep(1000000);
                }
                return null;
            }
            
            public static void main(string[] args)
            {
                var inst = new BrokenThread();
                try {
                    Thread.create(inst.a_method, false);
                } catch (ThreadError e){}
            }
        }
        
The compiler output is:

BrokenThread.vala:9.9-9.20: warning: unreachable code detected
        return null;
        ^^^^^^^^^^^^
/home/albx/Projects/tests/BrokenThread.vala.c: In function ‘broken_thread_a_method’:
/home/albx/Projects/tests/BrokenThread.vala.c:67: error: ‘result’ undeclared (first use in this function)
/home/albx/Projects/tests/BrokenThread.vala.c:67: error: (Each undeclared identifier is reported only once
/home/albx/Projects/tests/BrokenThread.vala.c:67: error: for each function it appears in.)

In fact, the generated ‘broken_thread_a_method’ is like this:

static void* broken_thread_a_method (BrokenThread* self) {
                g_return_val_if_fail (self != NULL, NULL);
                while (TRUE) {
                        g_usleep ((gulong) 1000000);
                }
                result = NULL;
                return result;
        }
        
Regards
Alberto

This email has been scanned for all viruses by the MessageLabs Email
Security System.



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