[Vala] Code generation bugs



Hello,

I've been playing with Vala a bit and, while very impressed, I've found
a few things that look like bugs. Alternatively, they may just be me
trying to do things I'm not allowed to do...

This is all with vala 0.3.3 on i386 Linux.



(a)

This code fragment:

void function(int a) throws IOError
{
        TestObject o = new TestObject();
        throw new TestError.FNORD("test error");
}

...compiles to:

static void function (gint a, GError** error) {
        GError * inner_error;
        TestObject* o;
        inner_error = NULL;
        o = test_object_new ();
        inner_error = g_error_new (TEST_ERROR, TEST_ERROR_FNORD,
                "test error");
        if (inner_error != NULL) {
                g_propagate_error (error, inner_error);
                return;
        }
        (o == NULL ? NULL : (o = (g_object_unref (o), NULL)));
}

That looks to me like the reference to o isn't being dropped when the
error gets thrown. Is this supposed to, er, not happen?



(b)

This piece of standalone code:

using GLib;

class TestObject : GLib.Object
{
}

public TestObject o;

...fails to compile with this error:

In file included from test.c:2:
test.h:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’
before ‘*’ token
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)

Looking at test.h, it contains:

G_BEGIN_DECLS
extern TestObject* o;
G_END_DECLS

...with no declaration of TestObject. This appears wrong to me.



(c)

This code fragment:

delegate int FPtr(int a);
int test(int arg)
{
        FPtr f = (a) => { return a + arg; };
        return f(arg);
}

...compiles to the following code:

static gint __lambda0 (gint a) {
        return a + arg;
}

static gint ___lambda0_fptr (gint a, gpointer self) {
        return __lambda0 (a);
}

static gint test (gint arg) {
        FPtr _tmp0;
        void* f_target;
        FPtr f;
        f = (_tmp0 = ___lambda0_fptr, f_target = NULL, _tmp0);
        return f (arg, f_target);
}

Note that __lambda0() is referring to arg, which is actually defined as
an argument to test(); this fails to compile. Now, I'm aware that this
sort of behaviour is one of the traditionally Really Hard things to
implement in a static language like C, but it probably shouldn't produce
bad code in quite this manner (putting, for example, 'public int arg' at
the top of your program will make it compile erroneously quite happily).

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature



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