magic-lang / rock

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

Override function definition fix #59

Closed thomasfanell closed 8 years ago

thomasfanell commented 8 years ago

We want to prevent this from compiling:

Foo: abstract class <T> {
    test: abstract func (value: T) -> Int
}
Bar: class <T> extends Foo<T> {
    init: func
    // this will currently compile just fine...
    test: override func (value: T*) -> Int {
        1337
    }
}
bar := Bar<Int> new()

@shamanas @zhaihj The fix works as expected, but is it too sloppy or plain naive? Suggestions?

marcusnaslund commented 8 years ago

Does this also prevent when T or T* is inside a Func given as argument?

thomasfanell commented 8 years ago

@marcusnaslund it does now :)

This will generate an error now:

Foo: abstract class <T> {
    test: abstract func (value: T, fn: Func(T) -> Int) -> Int
}
Bar: class <T> extends Foo<T> {
    init: func
    test: override func (value: T, fn: Func(T*) -> Int) -> Int {
        fn(value&)
    }
}
bar := Bar<Int> new()
marcusnaslund commented 8 years ago

Excellent. :)

alexnask commented 8 years ago

Personally I think it's fine, although I do think algo/typeAnalysis.ooc should have tools to help with this kind of thing (but iirc there is nothing about generics in there).

thomasfanell commented 8 years ago

@shamanas thanks, I think we'll settle with this for now then.

thomasfanell commented 8 years ago

Merged via #61