Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes rock crashes when implementing interfaces #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexnask
Copy link

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
Copy link

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
Copy link

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

@alexnask
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants