diff options
author | Paul Phillips <paulp@improving.org> | 2011-08-24 17:11:55 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-08-24 17:11:55 +0000 |
commit | b9785280a7138a2bb52060faf94807aa0d07dec1 (patch) | |
tree | 870cc1930ac3d50cd07078260f58984224dd39a5 /test/files/pos/t592.scala | |
parent | 84fcf633d9ca507124806d64729cb8463bcebb69 (diff) | |
download | scala-b9785280a7138a2bb52060faf94807aa0d07dec1.tar.gz scala-b9785280a7138a2bb52060faf94807aa0d07dec1.tar.bz2 scala-b9785280a7138a2bb52060faf94807aa0d07dec1.zip |
Renamed tests named bugXXX to tXXX, no review.
Diffstat (limited to 'test/files/pos/t592.scala')
-rw-r--r-- | test/files/pos/t592.scala | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/files/pos/t592.scala b/test/files/pos/t592.scala new file mode 100644 index 0000000000..6a941ef51a --- /dev/null +++ b/test/files/pos/t592.scala @@ -0,0 +1,71 @@ +trait Graph { + type Edge; + type Node <: NodeIntf; + + trait NodeIntf { + def connectWith(node: Node): Edge; + } + + def nodes: List[Node]; + def edges: List[Edge]; + def addNode: Node; + + protected var ids = 0; +} + +abstract class DirectedGraph extends Graph { + type Edge <: EdgeImpl; + + class EdgeImpl(origin: Node, dest: Node) { + def from = origin; + def to = dest; + override def toString = ""+origin+" --> "+dest + } + + class NodeImpl extends NodeIntf { self: Node => + val id = ids + ids = ids + 1 + def connectWith(node: Node): Edge = { + val edge = newEdge(this, node); + edges = edge :: edges; + edge; + } + override def toString = "Node "+id + } + + protected def newNode: Node; + protected def newEdge(from: Node, to: Node): Edge; + var nodes: List[Node] = Nil; + var edges: List[Edge] = Nil; + + def addNode: Node = { + val node = newNode; + nodes = node :: nodes; + node; + } +} + +class ConcreteDirectedGraph extends DirectedGraph { + type Edge = EdgeImpl; + type Node = NodeImpl; + + protected def newNode: Node = { + new NodeImpl; + } + + protected def newEdge(f: Node, t: Node): Edge = { + new EdgeImpl(f, t); + } +} + +object ExplicitThis { + def main(args: Array[String]): Unit = { + val g: Graph = new ConcreteDirectedGraph; + val n1 = g.addNode; + val n2 = g.addNode; + val n3 = g.addNode; + Console.println(n1.connectWith(n2)) + Console.println(n2.connectWith(n3)) + Console.println(n1.connectWith(n3)) + } +} |