aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-09 19:00:14 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-09 19:00:14 +0100
commita7b60116c30677eeff310b81af2fa714bf1950d6 (patch)
tree40de9fd78f40b0adfc6d2600b4f60f5b7721519b /tests
parent3bc8f5dceba014ddd0c7e5cc8080009439c5b363 (diff)
downloaddotty-a7b60116c30677eeff310b81af2fa714bf1950d6.tar.gz
dotty-a7b60116c30677eeff310b81af2fa714bf1950d6.tar.bz2
dotty-a7b60116c30677eeff310b81af2fa714bf1950d6.zip
New tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/neg/patternUnsoundness.scala17
-rw-r--r--tests/pos/Coder.scala18
-rw-r--r--tests/pos/Patterns.scala19
3 files changed, 43 insertions, 11 deletions
diff --git a/tests/neg/patternUnsoundness.scala b/tests/neg/patternUnsoundness.scala
new file mode 100644
index 000000000..b3d699a5c
--- /dev/null
+++ b/tests/neg/patternUnsoundness.scala
@@ -0,0 +1,17 @@
+object patternUnsoundness extends App {
+
+ class C[+T]
+
+ case class D[S](_s: S) extends C[S] {
+ var s: S = _s
+ }
+
+ val x = new D[String]("abc")
+ val y: C[Object] = x
+
+ y match {
+ case d @ D(x) => d.s = new Integer(1)
+ }
+
+ val z: String = x.s // ClassCast exception
+} \ No newline at end of file
diff --git a/tests/pos/Coder.scala b/tests/pos/Coder.scala
index a168dee4c..3fcda1afd 100644
--- a/tests/pos/Coder.scala
+++ b/tests/pos/Coder.scala
@@ -27,7 +27,6 @@ class Coder(words: List[String]) {
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
@@ -39,22 +38,19 @@ class Coder(words: List[String]) {
def encode(number: String): Set[List[String]] =
if (number.isEmpty) Set(Nil)
else {
- val x: List[List[String]] = ???
- x.toSet
- }
-*/
-/* for {
+ val xs = for {
splitPoint <- 1 to number.length
- word <- number take splitPoint
+ word <- wordsForNum(number take splitPoint)
rest <- encode(number drop splitPoint)
} yield word :: rest
-*/
+ xs.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 " ")
+ def translate(number: String): Set[String] = encode(number) map (_ mkString " ")
}
-/*
+
/** Test code */
object Coder {
def main(args : Array[String]) : Unit = {
@@ -62,4 +58,4 @@ object Coder {
// println(coder.wordsForNum)
println(coder.translate("7225276257"))
}
-}*/
+}
diff --git a/tests/pos/Patterns.scala b/tests/pos/Patterns.scala
new file mode 100644
index 000000000..1161e352b
--- /dev/null
+++ b/tests/pos/Patterns.scala
@@ -0,0 +1,19 @@
+object Patterns {
+ ('1', "1") match {
+ case (digit, str) => true
+ case _ => false
+ }
+
+ val xs = List('2' -> "ABC", '3' -> "DEF")
+
+ xs filter {
+ case (digit, str) => true
+ case _ => false
+ }
+
+ def sum(xs: List[Int]): Int = xs match {
+ case Nil => 0
+ case x :: xs1 => x + sum(xs1)
+ }
+
+} \ No newline at end of file