global Func objects #876

Closed
AlasdairWJ opened this Issue Apr 26, 2015 · 1 comment

Projects

None yet

2 participants

@AlasdairWJ

It seems rock doesn't recognize globally declared function objects.

myFunc: Func(Int)
myFunc_imp: func (i: Int) {
    "%d" printfln(i)
}
main: func {
    myFunc = myFunc_imp
    myFunc(10)
}

The compiler throws a 'No such function' error on myFunc(10). This also fails:

other := func {
    "Hi!" println()
}   
main: func {
    other()
}

but can however, be worked around like this:

f := myFunc
f(10)
g := other
g()
@zhaihj zhaihj added a commit to zhaihj/rock that referenced this issue Apr 27, 2015
@zhaihj zhaihj search for global functype vars
test from ooc-lang#876
e13f170
@fasterthanlime
Collaborator

My version of the test, using string interpolation & more importantly, making sure closures still work in that context:

x := 2

myFunc: Func (Int)

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

main: func {
    myFunc = myFunc_imp
    "before, x = #{x}" println()
    myFunc(10)
    "after, x = #{x}" println()
}
@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