magic-lang / rock

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

Fixes rock crashes when implementing interfaces #66

Open alexnask opened 8 years ago

alexnask commented 8 years ago

Specifically, when the implementor did not provide a (correct or incorrect) function of the same name and suffix as asked for or when the interface provides a default function.

thomasfanell commented 8 years ago
Printable: interface {
    print: func {
        "this is the default function" printfln()
    }
}

Foobar: class implements Printable {
    init: func
    print: func {
        "Hello from Foobar" printfln()
    }
}

test: func (object: Printable) {
    object print()
}

createPrintable: func -> Printable {
    Foobar new()
}

// Both of these print "this is the default function".
test(Foobar new())
createPrintable() print()
Printable: interface {
    print: func // now it works as expected
}

I am surprised that it's even allowed to provide implementations in an interface. I suppose this is per design, but what is the purpose of it?

As a side-note, it seems we both selected similar names for our tests (I didn't even see your test file until now). :-)

thomasfanell commented 8 years ago

Is this a shot at the bounty, by the way?

alexnask commented 8 years ago

@thomasfanell Weird bug, will take a look at it.

The purpose of allowing concrete functions in an interface is to basically abstract away operations that will be available for any class that implements it.

For example, if you had a Printable interface that requires a toString: func -> String function, it could make sense to provide a print and println (default) function.
Don't know if I explained it well enough.

This is not a shot at the bounty, by the way, I think a lot more stuff must be fixed regarding interfaces.