diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-13 20:51:57 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-13 20:51:57 +0000 |
commit | b6d1953b85bddc7ccd748fa8f8aa2b7d3eb1f194 (patch) | |
tree | b39ca3818b4803af062b561bc5342f8a7334e718 /test | |
parent | 32d2b15d5db3e9e582632cc8f995dcc362751d6a (diff) | |
download | scala-b6d1953b85bddc7ccd748fa8f8aa2b7d3eb1f194.tar.gz scala-b6d1953b85bddc7ccd748fa8f8aa2b7d3eb1f194.tar.bz2 scala-b6d1953b85bddc7ccd748fa8f8aa2b7d3eb1f194.zip |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/pos/implicit-unwrap-tc.scala | 10 | ||||
-rw-r--r-- | test/files/run/primitive-sigs-2.check | 4 | ||||
-rw-r--r-- | test/files/run/primitive-sigs-2.scala | 19 | ||||
-rw-r--r-- | test/files/run/repl-parens.check | 28 | ||||
-rw-r--r-- | test/files/run/repl-parens.scala | 4 |
5 files changed, 57 insertions, 8 deletions
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<java.lang.Object> interface scala.ScalaObject List(A, char, class java.lang.Object) a +public scala.collection.immutable.List<java.lang.Object> Arr.arr1(int[]) +public scala.collection.immutable.List<java.lang.Character> Arr.arr2(java.lang.Character[]) +public float[] Arr.arr3(float[][]) +public <T> java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest<T>) 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 <T> java.lang.Object Arr.arr4(java.lang.Object[],scala.reflect.Manifest<T>) + // + // instead of the more appealing version from the past + // public <T> T[] Arr.arr4(T[][],scala.reflect.Manifest<T>) + // + // 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 = <function0> +res11: () => Int = <function0> scala> 55 ; () => 5 -res8: () => Int = <function0> +res12: () => Int = <function0> scala> () => { class X ; new X } -res9: () => java.lang.Object with ScalaObject = <function0> +res13: () => java.lang.Object with ScalaObject = <function0> 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) |