Permalink
Browse files

Test cases.

Closes SI-4482, SI-4651, SI-3702.

Pending tests for SI-1832, SI-3439, SI-5091, SI-5231, SI-5265.
  • Loading branch information...
paulp committed May 5, 2012
1 parent e8ec9ea commit 4c04213b991596aa73dec3aa34cb8816a277f538
View
@@ -0,0 +1,12 @@
object Test {
def analyze(x: Any) = x match {
case s: String => println("It's a string: " + s)
case 1 => println("It's a one")
case (a: Int, b) => println("It's a pair of and int " + a +
" and something " + b)
case 1 :: 2 :: _ => println("It's a list starting with 1, 2")
case List(a, b, c) => println("It's a three-element list with " +
a + ", " + b + ", " + c)
case _ => println("It's something different")
}
}
@@ -0,0 +1,2 @@
()
6
View
@@ -0,0 +1,11 @@
object Test {
def foo(h: Any, t: List[Any]) = h match {
case 5 :: _ => ()
case List(from) => from
}
def main(args: Array[String]): Unit = {
println(foo(5 :: Nil, List(1,2,3)))
println(foo(6 :: Nil, List(1,2,3)))
}
}
@@ -0,0 +1 @@
2
View
@@ -0,0 +1,15 @@
trait Foo { def i: Int }
trait Bar
case class Spam(i: Int) extends Foo with Bar
object Test {
def matchParent(p:Any) = p match {
case f:Foo if f.i == 1 => 1
case _:Bar => 2
case _:Foo => 3
}
def main(args: Array[String]): Unit = {
println(matchParent(Spam(3)))
}
}
@@ -0,0 +1,10 @@
// Edit by paulp: reduced.
trait Cloning {
trait Foo
def fn(g: Int => Unit): Foo
implicit def mkStar(i: Int) = new { def *(a: Foo): Foo = null }
val pool1 = 4 * fn { case i => i * 2 }
val pool2 = 4 * fn { case i: Int => i * 2 }
}
@@ -0,0 +1,2 @@
abstract class ParametricMessage[M: Manifest](msg: M) { def message = msg }
case class ParametricMessage1[M: Manifest](msg: M, p1: Class[_]) extends ParametricMessage(msg)
@@ -0,0 +1,11 @@
object RecursiveValueNeedsType {
def foo(param: String) = 42
def bar(n: Int) = 42
{
val xxx = foo(param = null)
val param = bar(xxx)
}
}
@@ -0,0 +1,18 @@
object Client {
sealed trait ConfigLike {
def clientID: Int
}
object Config {
def apply() : ConfigBuilder = new ConfigBuilder()
implicit def build( cb: ConfigBuilder ) : Config = cb.build
}
final class Config private[Client]( val clientID: Int )
extends ConfigLike
final class ConfigBuilder private () extends ConfigLike {
var clientID: Int = 0
def build : Config = new Config( clientID )
}
}
@@ -0,0 +1,21 @@
import java.util.Date
trait TDate
trait TT[A1,T1]
trait TTFactory[F,G] {
def create(f: F) : TT[F,G]
def sample: F
}
object Impls {
// If the c1 is declared before c2, it compiles fine
implicit def c2(s: Date) = c1.create(s)
implicit val c1 = new TTFactory[Date,TDate] {
def create(v: Date): TT[Date,TDate] = sys.error("")
def sample = new Date
}
}

0 comments on commit 4c04213

Please sign in to comment.