From b6d1953b85bddc7ccd748fa8f8aa2b7d3eb1f194 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 13 Jun 2011 20:51:57 +0000 Subject: Test case for implicits which unwrap typeclasse... Test case for implicits which unwrap typeclasses, something which must really live on the edge given the multiple ways we've busted it lately. Also some Array/signature and repl tests. No review. --- test/files/pos/implicit-unwrap-tc.scala | 10 ++++++++++ test/files/run/primitive-sigs-2.check | 4 ++++ test/files/run/primitive-sigs-2.scala | 19 +++++++++++++++++++ test/files/run/repl-parens.check | 28 ++++++++++++++++++++-------- test/files/run/repl-parens.scala | 4 ++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 test/files/pos/implicit-unwrap-tc.scala (limited to 'test') diff --git a/test/files/pos/implicit-unwrap-tc.scala b/test/files/pos/implicit-unwrap-tc.scala new file mode 100644 index 0000000000..1afde26613 --- /dev/null +++ b/test/files/pos/implicit-unwrap-tc.scala @@ -0,0 +1,10 @@ +trait NewType[X] + +object Test { + // change return type to Foo and it compiles. + implicit def Unwrap[X](n: NewType[X]): X = sys.error("") + class Foo(val a: Int) + def test(f: NewType[Foo]) = f.a +} + + diff --git a/test/files/run/primitive-sigs-2.check b/test/files/run/primitive-sigs-2.check index 4ecec9f199..2a0b3179c1 100644 --- a/test/files/run/primitive-sigs-2.check +++ b/test/files/run/primitive-sigs-2.check @@ -1,3 +1,7 @@ T interface scala.ScalaObject List(A, char, class java.lang.Object) a +public scala.collection.immutable.List Arr.arr1(int[]) +public scala.collection.immutable.List Arr.arr2(java.lang.Character[]) +public float[] Arr.arr3(float[][]) +public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest) diff --git a/test/files/run/primitive-sigs-2.scala b/test/files/run/primitive-sigs-2.scala index a8876f7f60..b535e7c1fb 100644 --- a/test/files/run/primitive-sigs-2.scala +++ b/test/files/run/primitive-sigs-2.scala @@ -1,20 +1,39 @@ +import java.{ lang => jl } + trait T[A] { def f(): A } class C extends T[Char] { def f(): Char = 'a' } +class Arr { + def arr1(xs: Array[Int]): List[Int] = xs.toList + def arr2(xs: Array[jl.Character]): List[jl.Character] = xs.toList + def arr3(xss: Array[Array[Float]]): Array[Float] = xss map (_.sum) + // This gets a signature like + // public java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest) + // + // instead of the more appealing version from the past + // public T[] Arr.arr4(T[][],scala.reflect.Manifest) + // + // because java inflict's its reference-only generic-arrays on us. + // + def arr4[T: Manifest](xss: Array[Array[T]]): Array[T] = xss map (_.head) +} object Test { val c1: Class[_] = classOf[T[_]] val c2: Class[_] = classOf[C] + val c3: Class[_] = classOf[Arr] val c1m = c1.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) val c2m = c2.getMethods.toList filter (_.getName == "f") map (_.getGenericReturnType.toString) + val c3m = c3.getDeclaredMethods.toList map (_.toGenericString) def main(args: Array[String]): Unit = { println(c2.getGenericInterfaces.map(_.toString).sorted mkString " ") println(c1m ++ c2m sorted) println(new C f) + c3m foreach println } } diff --git a/test/files/run/repl-parens.check b/test/files/run/repl-parens.check index 79db06f272..f41c2e74bd 100644 --- a/test/files/run/repl-parens.check +++ b/test/files/run/repl-parens.check @@ -10,30 +10,42 @@ res1: Int = 4 scala> ((2 + 2)) res2: Int = 4 +scala> ((2 + 2)) +res3: Int = 4 + +scala> ( (2 + 2)) +res4: Int = 4 + +scala> ( (2 + 2 ) ) +res5: Int = 4 + +scala> 5 ; ( (2 + 2 ) ) ; ((5)) +res6: Int = 5 + scala> (((2 + 2)), ((2 + 2))) -res3: (Int, Int) = (4,4) +res7: (Int, Int) = (4,4) scala> (((2 + 2)), ((2 + 2)), 2) -res4: (Int, Int, Int) = (4,4,2) +res8: (Int, Int, Int) = (4,4,2) scala> ((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString) -res5: String = 4423 +res9: String = 4423 scala> scala> 55 ; ((2 + 2)) ; (1, 2, 3) -res6: (Int, Int, Int) = (1,2,3) +res10: (Int, Int, Int) = (1,2,3) scala> scala> () => 5 -res7: () => Int = +res11: () => Int = scala> 55 ; () => 5 -res8: () => Int = +res12: () => Int = scala> () => { class X ; new X } -res9: () => java.lang.Object with ScalaObject = +res13: () => java.lang.Object with ScalaObject = scala> @@ -41,6 +53,6 @@ scala> def foo(x: Int)(y: Int)(z: Int) = x+y+z foo: (x: Int)(y: Int)(z: Int)Int scala> foo(5)(10)(15)+foo(5)(10)(15) -res10: Int = 60 +res14: Int = 60 scala> diff --git a/test/files/run/repl-parens.scala b/test/files/run/repl-parens.scala index 3b2740837c..081db3606a 100644 --- a/test/files/run/repl-parens.scala +++ b/test/files/run/repl-parens.scala @@ -5,6 +5,10 @@ object Test extends ReplTest { (2) (2 + 2) ((2 + 2)) + ((2 + 2)) + ( (2 + 2)) + ( (2 + 2 ) ) +5 ; ( (2 + 2 ) ) ; ((5)) (((2 + 2)), ((2 + 2))) (((2 + 2)), ((2 + 2)), 2) ((((2 + 2)), ((2 + 2)), 2).productIterator ++ Iterator(3) mkString) -- cgit v1.2.3