Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning closures, double-wrapping in struct Closure #884

fasterthanlime opened this issue Jul 8, 2015 · 0 comments


Copy link

commented Jul 8, 2015

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()
    "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')
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) { 
    lang_types__Closure __issue876_closure14 = (lang_types__Closure) { 
    lang_types__Closure myFunc_imp = __issue876_closure14;
    myFunc = (lang_types__Closure) { 
// line 96, myFunc_imp is already a struct Closure.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.