diff options
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/classtags_core.check | 60 | ||||
-rw-r--r-- | test/files/run/macro-expand-implicit-argument.check | 1 | ||||
-rw-r--r-- | test/files/run/macro-expand-implicit-argument.flags | 1 | ||||
-rw-r--r-- | test/files/run/macro-expand-implicit-argument/Macros_1.scala | 59 | ||||
-rw-r--r-- | test/files/run/macro-expand-implicit-argument/Test_2.scala | 4 | ||||
-rw-r--r-- | test/files/run/t6052.scala | 21 |
6 files changed, 116 insertions, 30 deletions
diff --git a/test/files/run/classtags_core.check b/test/files/run/classtags_core.check index 2241108ba0..6519db2178 100644 --- a/test/files/run/classtags_core.check +++ b/test/files/run/classtags_core.check @@ -1,30 +1,30 @@ -true -ClassTag[byte] -true -ClassTag[short] -true -ClassTag[char] -true -ClassTag[int] -true -ClassTag[long] -true -ClassTag[float] -true -ClassTag[double] -true -ClassTag[boolean] -true -ClassTag[void] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class java.lang.Object] -true -ClassTag[class scala.runtime.Null$] -true -ClassTag[Nothing] +true
+ClassTag[byte]
+true
+ClassTag[short]
+true
+ClassTag[char]
+true
+ClassTag[int]
+true
+ClassTag[long]
+true
+ClassTag[float]
+true
+ClassTag[double]
+true
+ClassTag[boolean]
+true
+ClassTag[void]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class java.lang.Object]
+true
+ClassTag[class scala.runtime.Null$]
+true
+ClassTag[class scala.runtime.Nothing$]
diff --git a/test/files/run/macro-expand-implicit-argument.check b/test/files/run/macro-expand-implicit-argument.check new file mode 100644 index 0000000000..fb42345748 --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument.check @@ -0,0 +1 @@ +List(1, 2, 3)
diff --git a/test/files/run/macro-expand-implicit-argument.flags b/test/files/run/macro-expand-implicit-argument.flags new file mode 100644 index 0000000000..cd66464f2f --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument.flags @@ -0,0 +1 @@ +-language:experimental.macros
\ No newline at end of file diff --git a/test/files/run/macro-expand-implicit-argument/Macros_1.scala b/test/files/run/macro-expand-implicit-argument/Macros_1.scala new file mode 100644 index 0000000000..7629c5a9e2 --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument/Macros_1.scala @@ -0,0 +1,59 @@ +import annotation.tailrec +import scala.math.{min, max} +import scala.{specialized => spec} + +import language.experimental.macros + +import scala.reflect.{ClassTag, TypeTag} +import scala.reflect.macros.Context + +object Macros { + def alloc[@spec A:ClassTag](src:Array[A], s1:Int, len:Int) = { + val as = Array.ofDim[A](len) + System.arraycopy(src, s1, as, 0, len) + as + } + + /** + * Efficient alternative to Array.apply. + * + * "As seen on scala-internals!" + */ + def array[A](as:A*)(implicit ct: ClassTag[A]) = macro arrayMacro[A] + + /** + * Takes in something like: + * ArrayUtil.alloc[Int](11, 22, 33, 44)(ct) + * + * and builds a tree like: + * { + * val arr:Array[Int] = ct.newArray(4) + * arr.update(0, 11) + * arr.update(1, 22) + * arr.update(2, 33) + * arr.update(3, 44) + * arr + * } + */ + def arrayMacro[A:c.AbsTypeTag](c:Context)(as:c.Expr[A]*)(ct: c.Expr[ClassTag[A]]): c.Expr[Array[A]] = { + import c.mirror._ + import c.universe._ + def const(x:Int) = Literal(Constant(x)) + + val n = as.length + val arr = newTermName("arr") + + val create = Apply(Select(ct.tree, "newArray"), List(const(n))) + val arrtpe = TypeTree(implicitly[c.AbsTypeTag[Array[A]]].tpe) + val valdef = ValDef(Modifiers(), arr, arrtpe, create) + + val updates = (0 until n).map { + i => Apply(Select(Ident(arr), "update"), List(const(i), as(i).tree)) + } + + val exprs = Seq(valdef) ++ updates ++ Seq(Ident(arr)) + val block = Block(exprs:_*) + + c.Expr[Array[A]](block) + } +}
\ No newline at end of file diff --git a/test/files/run/macro-expand-implicit-argument/Test_2.scala b/test/files/run/macro-expand-implicit-argument/Test_2.scala new file mode 100644 index 0000000000..ce8a068fb4 --- /dev/null +++ b/test/files/run/macro-expand-implicit-argument/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + println(array(1, 2, 3).toList) +}
\ No newline at end of file diff --git a/test/files/run/t6052.scala b/test/files/run/t6052.scala new file mode 100644 index 0000000000..385d5390d3 --- /dev/null +++ b/test/files/run/t6052.scala @@ -0,0 +1,21 @@ + + + + + + + +object Test extends App { + def seqarr(i: Int) = Array[Int]() ++ (0 until i) + def pararr(i: Int) = seqarr(i).par + + def check[T](i: Int, f: Int => T) { + val gseq = seqarr(i).toSeq.groupBy(f) + val gpar = pararr(i).groupBy(f) + assert(gseq == gpar, (gseq, gpar)) + } + + for (i <- 0 until 20) check(i, _ > 0) + for (i <- 0 until 20) check(i, _ % 2) + for (i <- 0 until 20) check(i, _ % 4) +} |