Fixes rock crashes when implementing interfaces#66
Fixes rock crashes when implementing interfaces#66alexnask wants to merge 1 commit intomagic-lang:masterfrom
Conversation
…fault interface provided functions
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). :-) |
|
Is this a shot at the bounty, by the way? |
|
@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 This is not a shot at the bounty, by the way, I think a lot more stuff must be fixed regarding interfaces. |
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.