Skip to content

Commit

Permalink
Small changes to test
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Mar 26, 2018
1 parent f019062 commit 59e3977
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/pos/commons.scala
Expand Up @@ -7,10 +7,10 @@ trait Text {
def apply(idx: Int): Char
def concat(txt: Text): Text
def toStr: String
def flatten = `common`.fromString(toStr)
}
object Text {
trait Common { self =>
type Instance <: Text { val `common`: self.type }
def fromString(str: String): Text
def fromStrings(strs: String*): Text =
("" :: strs.toList).map(fromString).reduceLeft(_.concat(_))
Expand All @@ -19,13 +19,14 @@ object Text {

class FlatText(str: String) extends Text {
val common: FlatText.type = FlatText
import `common`._

def length = str.length
def apply(n: Int) = str.charAt(n)
def concat(txt: Text) = new FlatText(str ++ txt.toStr)
def toStr = str
}
object FlatText extends Text.Common {
type Instance = FlatText
def fromString(str: String) = new FlatText(str)
}

Expand All @@ -45,7 +46,7 @@ enum ConcText extends Text {
case Conc(t1, t2) => if (n < t1.length) t1(n) else t2(n - t1.length)
}

def concat(txt: Text) = Conc(this, txt)
def concat(txt: Text): Text = Conc(this, txt)

def toStr: String = this match {
case Str(s) => s
Expand All @@ -54,7 +55,6 @@ enum ConcText extends Text {
}

object ConcText extends Text.Common {
type Instance = ConcText
def fromString(str: String) = Str(str)
}

Expand Down

0 comments on commit 59e3977

Please sign in to comment.