Permalink
Browse files

test from stef for #485

  • Loading branch information...
gavinking committed Nov 6, 2012
1 parent 89371a2 commit 1e4eeaf172e7b7718756b25bfc3c7e38554a1e82
Showing with 32 additions and 0 deletions.
  1. +32 −0 test/main/typing/BrokenSelfTypes.ceylon
@@ -0,0 +1,32 @@
+@error abstract class Tree() satisfies Summable<Tree|Integer>{
+ shared actual Tree plus(Tree|Integer other) {
+ return Addition(this, other);
+ }
+ shared formal Integer evaluate();
+}
+
+class BinaryOperator(Tree|Integer left, Tree|Integer right, Integer f(Integer a, Integer b)) extends Tree(){
+ Integer resolve(Tree|Integer node){
+ switch(node)
+ case (is Tree){
+ return node.evaluate();
+ }
+ case (is Integer){
+ return node;
+ }
+ }
+
+ shared actual Integer evaluate() {
+ return f(resolve(left), resolve(right));
+ }
+
+ shared actual default String string = "Binary(" left ", " right ")";
+}
+
+class Multiplication(Tree|Integer left, Tree|Integer right) extends BinaryOperator(left, right, (Integer a, Integer b) a * b) {
+ shared actual default String string = "(" left " * " right ")";
+}
+
+class Addition(Tree|Integer left, Tree|Integer right) extends BinaryOperator(left, right, (Integer a, Integer b) a + b) {
+ shared actual default String string = "(" left " + " right ")";
+}

0 comments on commit 1e4eeaf

Please sign in to comment.