ooc-lang / rock

:ocean: self-hosted ooc compiler that generates c99
http://ooc-lang.org/
MIT License
404 stars 40 forks source link

Rock does not correctly call non-ACS generic function arguments #934

Open alexnask opened 9 years ago

alexnask commented 9 years ago

As pointed out in #923

The following code:

foo: func <T> (T: Class, obj: T, f: Func (T)) {
    f(obj)
}

bar: func (s: String) {
    s println()
    stdout flush()
}

baz := func (s: String) {
    s println()
    stdout flush()
}

foo(String, "Hello ACS", |s|
    s println()
    stdout flush()
)

foo(String, "Hello func", bar)

foo(String, "Hello object func", baz)

foo(String, "Hello func closure", func (s: String) {
    s println()
    stdout flush()
})

Only outputs "Hello ACS" before segfaulting, should print everything after I'm done with it

alexnask commented 9 years ago

Actually, my objective is making the func closure work as well and throw warnings on the other cases.

alexnask commented 9 years ago

The fix is actually pretty simple, the definitions added to closures that take a generic and turn it into the actual type were only applied to ACS closures for some reason.

By changing that to any closure when we can find a FunctionCall in the resolver's trail, they are applied to func { ... } closures as well.

Nowlet's implement a warning for non-closure functions passed!
(When we pass a generic argument when the function doesn't define it as generic, that should do the trick)