Assigning closures, double-wrapping in struct Closure #884

Closed
fasterthanlime opened this Issue Jul 8, 2015 · 0 comments

Projects

None yet

1 participant

@fasterthanlime
Collaborator

Test code

A twist on #876's sample:

main: func {
    x := 2

    myFunc: Func (Int)

    myFunc_imp := func (i: Int) {
        "i = #{i}" println()
        x = 4
    }

    myFunc = myFunc_imp
    "before, x = #{x}" println()
    myFunc(10)
    "after, x = #{x}" println()
}

Expected result

Should compile, run, and print:

before, x = 2
i = 10
after, x = 4

Current result

Invalid C gets generated:

$ rock -r --nolines issue876
rock_tmp/ooc/issue876/issue876.c:96:9: error: initializing 'lang_types__Pointer'
      (aka 'void *') with an expression of incompatible type 'lang_types__Closure' (aka
      'struct _lang_types__Closure')
        myFunc_imp,
        ^~~~~~~~~~
1 error generated.
C compiler failed on module issue876 from issue876, bailing out

Relevant .c snippet:

// line 84
    lang_Numbers__Int x = 2;
    lang_types__Closure myFunc;
    __issue876_issue876_closure12_ctx* __issue876_ctx13 = lang_Memory__gc_malloc(((lang_types__Class*)__issue876_issue876_closure12_ctx_class())->size);
    (*(__issue876_ctx13)) = (__issue876_issue876_closure12_ctx) { 
        &(x)
    };
    lang_types__Closure __issue876_closure14 = (lang_types__Closure) { 
        issue876____issue876_issue876_closure12_thunk, 
        __issue876_ctx13
    };
    lang_types__Closure myFunc_imp = __issue876_closure14;
    myFunc = (lang_types__Closure) { 
// line 96, myFunc_imp is already a struct Closure.
        myFunc_imp, 
        NULL
    };

Not really planning on fixing it right this moment, but I don't think it should be too hard.

@fasterthanlime fasterthanlime added a commit that closed this issue Jul 8, 2015
@fasterthanlime fasterthanlime Closes #884 aa2bebe
@fasterthanlime fasterthanlime modified the milestone: 0.9.10 Jul 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment