[Vala] Possible bug in generics support



I think I may have found a small bug in the usage of static delegates with Vala generic types. Basically, I think Vala ought to enforce that if I refer to the variable type in a delegate defined in a generic, I mean the version associated with specific version of the generic in use.

Here's an example, as simple as I can make it, with comments illustrating the behavior I'd expect:

=======================

class Holder<HeldObject> : Object
{
    public HeldObject myObject;
    public static delegate bool Frobulator(HeldObject object);
    public bool frobulateHeld(Frobulator f) {
        return f(myObject);
    }
}

public class ClassA : Object
{
    public int thing1;
    public bool frobulate() { return thing1 == 42; }
}
public class ClassB : Object
{
    public int thing2;
    public bool frobulate() { return thing2 == 42; }
}

public class Main
{
public static bool frobulateA(ClassA object) { return object.thing1 == 42; } public static bool frobulateB(ClassB object) { return object.thing2 == 42; }
    public static void main(string[] args) {
        Holder<ClassA> ha = new Holder<ClassA>();
        ha.myObject = new ClassA();
        ha.myObject.thing1 = 42;
        ha.frobulateHeld(ClassA.frobulate); // 1 ok
        ha.frobulateHeld(ClassB.frobulate); // 2 ok, should compile error
        // ha.frobulateHeld(Main.frobulateA); // 3 compile error, should ok
        // ha.frobulateHeld(Main.frobulateB); // 4 compile error
    }
}

=======================

In this case, I expect frobulateHeld for a Holder<X> to implicitly take a delegate that's of the type Holder<X>.Frobulator, which in turn requires an X as a first parameter, whether implicitly or explicitly. This is fairly easy to work around by casting where needed, a fix would improve the reliability of the Vala compiler as an screen for legitimate errors.

I can file this as a ticket if this is still in 0.6 (I'm on 0.5.7) and there's general consensus that this is a genuine bug. I just wanted to sanity check a bit first though.

--
Walter Mundt
emage spamcop net



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