Accessing generic member variables produces invalid (read: uncasted) code #425

Closed
nddrylliog opened this Issue Jun 7, 2012 · 2 comments

Projects

None yet

3 participants

@nddrylliog
Member

The following ooc code:

Jar: class <Z> {
    cookie: Z

    init: func (=cookie)
}

#specialize Jar<Int>

main: func {
    j := Jar<Int> new(42 as Int) 
    printf("j's cookie = %d\n", j cookie)

    k := Jar new("Folks")
    printf("k's cookie = %s\n", k cookie)
}

Produces stuff like that for the main func:

lang_Numbers__Int main() {
    GC_INIT();
    no_getter_load();
    no_getter__Jar___specialized1* j = no_getter__Jar___specialized1_new(((lang_Numbers__Int) (42)));
    lang_IO__printf(lang_string____OP_AS_String__Char__star(__strLit2), j->cookie);
    no_getter__Jar* k = no_getter__Jar_new((lang_core__Class*)lang_string__String_class(), (uint8_t*) &(__strLit3));
    lang_IO__printf(lang_string____OP_AS_String__Char__star(__strLit4), k->cookie);
    return ((lang_Numbers__Int) (0));
}

Which is obviously very wrong, the second printf should be:

    lang_IO__printf(lang_string____OP_AS_String__Char__star(__strLit4), *((char**) k->cookie));

Well, with the additional rock-ish underscore orgy, but you get the idea.

@shamanas
Collaborator

Here are two other related (kinda) bugs:

cell := Cell new(42)
fourtytwo := cell val // ERROR Undefined symbol 'T'
cell := Cell new(42)
cell val class name println()

This generates the following C code:

test__cell = lang_core__Cell_new((lang_core__Class*)lang_Numbers__SSizeT_class(), (uint8_t*) &(__genArg107));
lang_string__String_println(T->name);
@fasterthanlime
Collaborator

Ah, there we go. That was fixed as #889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment