Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions source/rock/middle/InterfaceImpl.ooc
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ InterfaceImpl: class extends ClassDecl {
finalScore : Int
value := impl getMeta() getFunction(key getName(), key getSuffix(), null, true, finalScore&)

// Check for the score between declarations
finalScore = value getScore(key)
if(finalScore == -1) {

res wholeAgain(this, "Not finished checking every function is implemented")
return Response OK

} else if(finalScore < 0) {
res throwError(InterfaceContractNotSatisfied new(value token,
"%s implements function %s, from interface %s, incorrectly\n" format(
impl getName(), key toString(), superType toString())))
}

if(value == null) {
if (value) {
// Check for the score between declarations
finalScore = value getScore(key)
if(finalScore == -1) {

res wholeAgain(this, "Not finished checking every function is implemented")
return Response OK

} else if(finalScore < 0) {
res throwError(InterfaceContractNotSatisfied new(value token,
"%s implements function %s, from interface %s, incorrectly\n" format(
impl getName(), key toString(), superType toString())))
}
} else {
if(impl instanceOf?(ClassDecl) && impl as ClassDecl isAbstract) {
// relay unimplemented interface methods into an abstract class...
value = FunctionDecl new(key getName(), key token)
Expand Down Expand Up @@ -100,6 +100,7 @@ InterfaceImpl: class extends ClassDecl {
}
}
}

aliases put(hash, FunctionAlias new(key, value))
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/compiler/interfaces/interface-provided-function.ooc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Printable: interface {
toString: func -> String

print: func {
toString() println()
}
}

Foo: class implements Printable {
count := static 0

init: func {
count += 1
}

toString: func -> String { "foo##{count}" }
}

describe("interfaces should be able to provide default implementations without rock crashing", ||
expect("foo#1", Foo new() toString())
)