aboutsummaryrefslogtreecommitdiff
path: root/tests/pos
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-10-30 17:09:34 +0100
committerMartin Odersky <odersky@gmail.com>2014-11-09 10:17:34 +0100
commit250418e830bc7ccacf13cb0d3a9121238d99632a (patch)
tree4acd1112a048d3299557deb17de920d343fc1ac3 /tests/pos
parentd907f26da9f0d3625a4c35021993f04a553bd354 (diff)
downloaddotty-250418e830bc7ccacf13cb0d3a9121238d99632a.tar.gz
dotty-250418e830bc7ccacf13cb0d3a9121238d99632a.tar.bz2
dotty-250418e830bc7ccacf13cb0d3a9121238d99632a.zip
New phase: PrivateToStatic
Make private methods in traits static, so that we do not need to give a default for them.
Diffstat (limited to 'tests/pos')
-rw-r--r--tests/pos/CoderTrait.scala63
-rw-r--r--tests/pos/privates.scala9
-rw-r--r--tests/pos/traits.scala25
3 files changed, 97 insertions, 0 deletions
diff --git a/tests/pos/CoderTrait.scala b/tests/pos/CoderTrait.scala
new file mode 100644
index 000000000..1eba60097
--- /dev/null
+++ b/tests/pos/CoderTrait.scala
@@ -0,0 +1,63 @@
+import collection.mutable.HashMap
+
+trait CoderTrait {
+
+ val words: List[String]
+
+ (2 -> "ABC", new ArrowAssoc('3') -> "DEF")
+
+ private val mnemonics = Map(
+ '2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
+ '6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
+
+
+ ('1', "1") match {
+ case (digit, str) => true
+ case _ => false
+ }
+
+ /** Invert the mnemonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
+ private val charCode0: Map[Char, Char] = mnemonics withFilter {
+ case (digit, str) => true
+ case _ => false
+ } flatMap { x$1 =>
+ x$1 match {
+ case (digit, str) => str map (ltr => ltr -> digit)
+ }
+ }
+
+ private val charCode: Map[Char, Char] =
+ for ((digit, str) <- mnemonics; ltr <- str) yield ltr -> digit
+
+ /** Maps a word to the digit string it can represent */
+ private def wordCode(word: String): String = word map charCode
+
+ /** A map from digit strings to the words that represent them */
+ private val wordsForNum: Map[String, List[String]] =
+ words groupBy wordCode withDefaultValue Nil
+
+ /** All ways to encode a number as a list of words */
+ def encode(number: String): Set[List[String]] =
+ if (number.isEmpty) Set(Nil)
+ else {
+ for {
+ splitPoint <- 1 to number.length
+ word <- wordsForNum(number take splitPoint)
+ rest <- encode(number drop splitPoint)
+ } yield word :: rest
+ }.toSet
+
+ /** Maps a number to a list of all word phrases that can represent it */
+ def translate(number: String): Set[String] = encode(number) map (_ mkString " ")
+
+}
+
+object Coder {
+ def main(args : Array[String]) : Unit = {
+ val coder = new CoderTrait {
+ val words = List("Scala", "sobls", "Python", "Ruby", "C", "A", "rocks", "sucks", "works", "Racka")
+ }
+// println(coder.wordsForNum)
+ println(coder.translate("7225276257"))
+ }
+}
diff --git a/tests/pos/privates.scala b/tests/pos/privates.scala
new file mode 100644
index 000000000..edaa10cb6
--- /dev/null
+++ b/tests/pos/privates.scala
@@ -0,0 +1,9 @@
+trait Test {
+
+ private val x = 2
+
+ private def foo() = x * x
+
+ private def bar() = foo()
+
+}
diff --git a/tests/pos/traits.scala b/tests/pos/traits.scala
new file mode 100644
index 000000000..15310d5a4
--- /dev/null
+++ b/tests/pos/traits.scala
@@ -0,0 +1,25 @@
+trait B {
+
+ val z: Int
+
+}
+
+trait T {
+
+ var x = 2
+
+ private var xp = 2
+
+ val y = 3
+
+ private val yp = 3
+
+ val z = 4
+
+ x = 4
+
+ xp = 4
+
+}
+
+class C extends T