ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
401 stars 40 forks source link

rock generates invalid C code when trying to access an interface's generic type #996

Open alexnask opened 8 years ago

alexnask commented 8 years ago
CraaazyInterface: interface <T> {
    gimme: func -> T

    doCraaazyThings: func {
        T name println()
    }
}

Generated code:

void test__CraaazyInterface_doCraaazyThings_impl(CraaazyInterface__reference this) {
    #line 5 "C:\\dev\\test.ooc"
    lang_String__String_println(this->T->name);
}

// Somewhere in a header file
struct _CraaazyInterface__reference {
    test__CraaazyInterfaceClass* impl;
    lang_types__Object* obj;
};

struct _test__CraaazyInterfaceClass {
    struct _lang_types__ClassClass __super__;
    void (*gimme)(void*, uint8_t*);
    void (*doCraaazyThings)(void*);
};

Basically, there is no way to get to T from an interface reference.

alexnask commented 8 years ago

T should probably live in CraaazyInterface__reference in the generated code.

alexnask commented 8 years ago

Well, technically T can be accessed in some way through obj but the whole point is that we do not know the type of obj, so we can't cast it to the actual object type of the current interface reference passed to access it.