magic-lang / rock

ooc compiler written in ooc
http://ooc-lang.org/
MIT License
14 stars 4 forks source link

Failure when trying to pass bracket operator as argument to a callback function in generic class #69

Open ghost opened 8 years ago

ghost commented 8 years ago

I'm bad at naming threads.

Foo: class <T> {
    _t: T
    init: func (=_t)
    bar: func (callback: Func (T*) -> Bool) {
        if (callback(this[0]&)) {
        } else {
        }
    }
    operator[] (index: Int) -> T {
        _t
    }
}

magic-lang rock compiler 1.0.20 file.ooc: In function ‘file__Foo_bar’: file.ooc:6:5: error: ‘else’ without a previous ‘if’ } else { ^

Workaround (@marcusnaslund ) :

Foo: class <T> {
    _t: T
    init: func (=_t)
    bar: func (callback: Func (T*) -> Bool) {
        ok: Bool
        ok = callback(this[0]&)
        if (ok) {
        } else {
        }
    }
    operator[] (index: Int) -> T {
        _t
    }
}
thomasfanell commented 8 years ago

Does ok: Bool = callback(this[0]&) work? We've had some issues with the short-hand := (declare-assign) operator before.

ghost commented 8 years ago

file__Foo_bar’: file.ooc:6:9: error: ‘ok’ undeclared (first use in this function) if (ok) { ^ C compiler failed on module okbug from okbug, bailing out