aboutsummaryrefslogtreecommitdiff
path: root/tests/pos/Coder.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-07 21:43:59 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-07 21:43:59 +0100
commit067ef2076cfcf7864b840ddf38c514ff67f52c64 (patch)
tree3b974ba717ecc08ab37d8dfb49c02f4f74d5eb5a /tests/pos/Coder.scala
parent514801453e240610a0ba68fff7305355a7d204e1 (diff)
downloaddotty-067ef2076cfcf7864b840ddf38c514ff67f52c64.tar.gz
dotty-067ef2076cfcf7864b840ddf38c514ff67f52c64.tar.bz2
dotty-067ef2076cfcf7864b840ddf38c514ff67f52c64.zip
Fixing inference problem and block scope problem
1. Typing blocks: forgot to create new scope. Now fixed. 2. The decitsion whether to interpolate a type variable was made based on the type variable's position and the current tree's position. This is too imprecise, because we might have auto-generated trees where all important parts have the same position. We now check for actual tree containment: A type variable can be interpolated for the type of a tree T if T contains the tree which introduced the type variable.
Diffstat (limited to 'tests/pos/Coder.scala')
-rw-r--r--tests/pos/Coder.scala44
1 files changed, 34 insertions, 10 deletions
diff --git a/tests/pos/Coder.scala b/tests/pos/Coder.scala
index 62ceebe80..a168dee4c 100644
--- a/tests/pos/Coder.scala
+++ b/tests/pos/Coder.scala
@@ -8,26 +8,50 @@ class Coder(words: List[String]) {
'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 charCode: Map[Char, Char] = mnemonics flatMap { ds =>
- val digit = ds._1
- val str = ds._2
- str map (ltr => ltr -> digit)
+ 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)
+ }
}
-// for ((digit, str) <- mnemonics; ltr <- str) yield 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 = ???
+ 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]] = ???
+ 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]] = ???
-
+ def encode(number: String): Set[List[String]] =
+ if (number.isEmpty) Set(Nil)
+ else {
+ val x: List[List[String]] = ???
+ x.toSet
+ }
+*/
+/* for {
+ splitPoint <- 1 to number.length
+ word <- number take splitPoint
+ rest <- encode(number drop splitPoint)
+ } yield word :: rest
+*/
+
/** Maps a number to a list of all word phrases that can represent it */
- def translate(number: String): Set[String] = encode(number) map (_ mkString " ")
+// def translate(number: String): Set[String] = encode(number) map (_ mkString " ")
}
/*