Permalink
Browse files

Merge pull request #999 from shamanas/interface_segfault

Fixes rock crashes regarding interfaces
  • Loading branch information...
alexnask committed May 11, 2016
2 parents 8a0becc + 9f91369 commit 079f9b970e2bf33bfa613c670c3d88cea99ac26e
Showing with 36 additions and 14 deletions.
  1. +15 −14 source/rock/middle/InterfaceImpl.ooc
  2. +21 −0 test/compiler/interfaces/interface-provided-function.ooc
@@ -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)
@@ -100,6 +100,7 @@ InterfaceImpl: class extends ClassDecl {
}
}
}
+
aliases put(hash, FunctionAlias new(key, value))
}
}
@@ -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())
+)

0 comments on commit 079f9b9

Please sign in to comment.