summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-05-11 12:14:19 -0700
committerEugene Burmako <xeno.by@gmail.com>2013-05-11 12:14:19 -0700
commitaa7568e8161552952ae16e0a5a79ce3ea517abe3 (patch)
tree679819f1381ec39b79169c2c21ca5d6acca72b63 /test/files
parent0ae7e55209129dc3d76d56887e88b2c817e6b904 (diff)
parent4e64a2731d6e4c27e2fd4c75559e118708e79ad5 (diff)
downloadscala-aa7568e8161552952ae16e0a5a79ce3ea517abe3.tar.gz
scala-aa7568e8161552952ae16e0a5a79ce3ea517abe3.tar.bz2
scala-aa7568e8161552952ae16e0a5a79ce3ea517abe3.zip
Merge pull request #2494 from scalamacros/ticket/5923
makes sense of implicit macros!
Diffstat (limited to 'test/files')
-rw-r--r--test/files/neg/macro-divergence-controlled.check4
-rw-r--r--test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala23
-rw-r--r--test/files/neg/macro-divergence-controlled/Test_2.scala3
-rw-r--r--test/files/neg/t5353.check4
-rw-r--r--test/files/neg/t5353.scala3
-rw-r--r--test/files/neg/t696a.check (renamed from test/files/neg/t696.check)2
-rw-r--r--test/files/neg/t696a.flags0
-rw-r--r--test/files/neg/t696a.scala (renamed from test/files/neg/t696.scala)0
-rw-r--r--test/files/neg/t696b.check9
-rw-r--r--test/files/neg/t696b.flags1
-rw-r--r--test/files/neg/t696b.scala7
-rw-r--r--test/files/neg/t7166.check4
-rw-r--r--test/files/neg/t7166/Impls_Macros_1.scala26
-rw-r--r--test/files/neg/t7166/Test_2.scala3
-rw-r--r--test/files/pos/t5692a.check (renamed from test/files/neg/t5692a.check)0
-rw-r--r--test/files/pos/t5692a.flags (renamed from test/files/neg/t5692a.flags)0
-rw-r--r--test/files/pos/t5692a/Macros_1.scala (renamed from test/files/neg/t5692a/Macros_1.scala)0
-rw-r--r--test/files/pos/t5692a/Test_2.scala (renamed from test/files/neg/t5692a/Test_2.scala)0
-rw-r--r--test/files/pos/t5692b.check (renamed from test/files/neg/t5692b.check)0
-rw-r--r--test/files/pos/t5692b.flags (renamed from test/files/neg/t5692b.flags)0
-rw-r--r--test/files/pos/t5692b/Macros_1.scala (renamed from test/files/neg/t5692b/Macros_1.scala)0
-rw-r--r--test/files/pos/t5692b/Test_2.scala (renamed from test/files/neg/t5692b/Test_2.scala)0
-rw-r--r--test/files/pos/t5692c.check0
-rw-r--r--test/files/pos/t5692c.scala4
-rw-r--r--test/files/run/macro-divergence-spurious.check1
-rw-r--r--test/files/run/macro-divergence-spurious/Impls_Macros_1.scala23
-rw-r--r--test/files/run/macro-divergence-spurious/Test_2.scala3
-rw-r--r--test/files/run/t5923a.check3
-rw-r--r--test/files/run/t5923a/Macros_1.scala14
-rw-r--r--test/files/run/t5923a/Test_2.scala5
-rw-r--r--test/files/run/t5923b.check3
-rw-r--r--test/files/run/t5923b/Test.scala7
-rw-r--r--test/files/run/t7047.check0
-rw-r--r--test/files/run/t7047/Impls_Macros_1.scala19
-rw-r--r--test/files/run/t7047/Test_2.scala3
-rw-r--r--test/files/run/t7291a.check1
-rw-r--r--test/files/run/t7291a.flags0
-rw-r--r--test/files/run/t7291a.scala19
-rw-r--r--test/files/run/t7291b.check2
-rw-r--r--test/files/run/t7291b.flags1
-rw-r--r--test/files/run/t7291b.scala19
41 files changed, 208 insertions, 8 deletions
diff --git a/test/files/neg/macro-divergence-controlled.check b/test/files/neg/macro-divergence-controlled.check
new file mode 100644
index 0000000000..4876f7cf96
--- /dev/null
+++ b/test/files/neg/macro-divergence-controlled.check
@@ -0,0 +1,4 @@
+Test_2.scala:2: error: could not find implicit value for parameter e: Complex[Foo]
+ println(implicitly[Complex[Foo]])
+ ^
+one error found
diff --git a/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala
new file mode 100644
index 0000000000..cdea3104a1
--- /dev/null
+++ b/test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala
@@ -0,0 +1,23 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+trait Complex[T]
+
+class Foo(val foo: Foo)
+
+object Complex {
+ def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = {
+ import c.universe._
+ val tpe = weakTypeOf[T]
+ for (f <- tpe.declarations.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) {
+ val trecur = appliedType(typeOf[Complex[_]], List(f.typeSignature))
+ if (c.openImplicits.tail.exists(ic => ic._1 =:= trecur)) c.abort(c.enclosingPosition, "diverging implicit expansion. reported by a macro!")
+ val recur = c.inferImplicitValue(trecur, silent = true)
+ if (recur == EmptyTree) c.abort(c.enclosingPosition, s"couldn't synthesize $trecur")
+ }
+ c.literalNull
+ }
+
+ implicit object ComplexString extends Complex[String]
+ implicit def genComplex[T]: Complex[T] = macro impl[T]
+}
diff --git a/test/files/neg/macro-divergence-controlled/Test_2.scala b/test/files/neg/macro-divergence-controlled/Test_2.scala
new file mode 100644
index 0000000000..dcc4593335
--- /dev/null
+++ b/test/files/neg/macro-divergence-controlled/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ println(implicitly[Complex[Foo]])
+} \ No newline at end of file
diff --git a/test/files/neg/t5353.check b/test/files/neg/t5353.check
deleted file mode 100644
index 75e2435600..0000000000
--- a/test/files/neg/t5353.check
+++ /dev/null
@@ -1,4 +0,0 @@
-t5353.scala:2: error: this type parameter must be specified
- def f(x: Boolean) = if (x) Array("abc") else Array()
- ^
-one error found
diff --git a/test/files/neg/t5353.scala b/test/files/neg/t5353.scala
deleted file mode 100644
index 1ee869aac1..0000000000
--- a/test/files/neg/t5353.scala
+++ /dev/null
@@ -1,3 +0,0 @@
-class A {
- def f(x: Boolean) = if (x) Array("abc") else Array()
-}
diff --git a/test/files/neg/t696.check b/test/files/neg/t696a.check
index ac26a864a5..490fc1a571 100644
--- a/test/files/neg/t696.check
+++ b/test/files/neg/t696a.check
@@ -1,4 +1,4 @@
-t696.scala:4: error: diverging implicit expansion for type TypeUtil0.Type[Any]
+t696a.scala:4: error: diverging implicit expansion for type TypeUtil0.Type[Any]
starting with method WithType in object TypeUtil0
as[Any](null);
^
diff --git a/test/files/neg/t696a.flags b/test/files/neg/t696a.flags
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/neg/t696a.flags
diff --git a/test/files/neg/t696.scala b/test/files/neg/t696a.scala
index a06a32141a..a06a32141a 100644
--- a/test/files/neg/t696.scala
+++ b/test/files/neg/t696a.scala
diff --git a/test/files/neg/t696b.check b/test/files/neg/t696b.check
new file mode 100644
index 0000000000..fcdb5440d8
--- /dev/null
+++ b/test/files/neg/t696b.check
@@ -0,0 +1,9 @@
+t696b.scala:5: error: diverging implicit expansion for type TypeUtil0.Type[Any]
+starting with method WithType in object TypeUtil0
+ as[Any](null)
+ ^
+t696b.scala:6: error: diverging implicit expansion for type TypeUtil0.Type[X]
+starting with method WithType in object TypeUtil0
+ def foo[X]() = as[X](null)
+ ^
+two errors found
diff --git a/test/files/neg/t696b.flags b/test/files/neg/t696b.flags
new file mode 100644
index 0000000000..d564f2b1f8
--- /dev/null
+++ b/test/files/neg/t696b.flags
@@ -0,0 +1 @@
+-Xdivergence211 \ No newline at end of file
diff --git a/test/files/neg/t696b.scala b/test/files/neg/t696b.scala
new file mode 100644
index 0000000000..ca76f7ef6c
--- /dev/null
+++ b/test/files/neg/t696b.scala
@@ -0,0 +1,7 @@
+object TypeUtil0 {
+ trait Type[+T]
+ implicit def WithType[S,T](implicit tpeS : Type[S], tpeT : Type[T]) : Type[S with T] = null
+ def as[T](x : Any)(implicit tpe : Type[T]) = null
+ as[Any](null)
+ def foo[X]() = as[X](null)
+}
diff --git a/test/files/neg/t7166.check b/test/files/neg/t7166.check
new file mode 100644
index 0000000000..c87198cb27
--- /dev/null
+++ b/test/files/neg/t7166.check
@@ -0,0 +1,4 @@
+Test_2.scala:2: error: silent = true does work!
+ println(implicitly[Complex[Foo]])
+ ^
+one error found
diff --git a/test/files/neg/t7166/Impls_Macros_1.scala b/test/files/neg/t7166/Impls_Macros_1.scala
new file mode 100644
index 0000000000..62a15657c3
--- /dev/null
+++ b/test/files/neg/t7166/Impls_Macros_1.scala
@@ -0,0 +1,26 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+trait Complex[T]
+
+class Foo
+
+object Complex {
+ def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = {
+ import c.universe._
+ def shout(msg: String) = {
+ val cannotShutMeUp = c.asInstanceOf[scala.reflect.macros.runtime.Context].universe.currentRun.currentUnit.error _
+ cannotShutMeUp(c.enclosingPosition.asInstanceOf[scala.reflect.internal.util.Position], msg)
+ }
+ try {
+ val complexOfT = appliedType(typeOf[Complex[_]], List(weakTypeOf[T]))
+ val infiniteRecursion = c.inferImplicitValue(complexOfT, silent = true)
+ shout("silent = true does work!")
+ } catch {
+ case ex: Exception => shout(ex.toString)
+ }
+ c.literalNull
+ }
+
+ implicit def genComplex[T]: Complex[T] = macro impl[T]
+}
diff --git a/test/files/neg/t7166/Test_2.scala b/test/files/neg/t7166/Test_2.scala
new file mode 100644
index 0000000000..dcc4593335
--- /dev/null
+++ b/test/files/neg/t7166/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ println(implicitly[Complex[Foo]])
+} \ No newline at end of file
diff --git a/test/files/neg/t5692a.check b/test/files/pos/t5692a.check
index 7fbfb5dba7..7fbfb5dba7 100644
--- a/test/files/neg/t5692a.check
+++ b/test/files/pos/t5692a.check
diff --git a/test/files/neg/t5692a.flags b/test/files/pos/t5692a.flags
index cd66464f2f..cd66464f2f 100644
--- a/test/files/neg/t5692a.flags
+++ b/test/files/pos/t5692a.flags
diff --git a/test/files/neg/t5692a/Macros_1.scala b/test/files/pos/t5692a/Macros_1.scala
index 06b5a3de36..06b5a3de36 100644
--- a/test/files/neg/t5692a/Macros_1.scala
+++ b/test/files/pos/t5692a/Macros_1.scala
diff --git a/test/files/neg/t5692a/Test_2.scala b/test/files/pos/t5692a/Test_2.scala
index 08d510cc6f..08d510cc6f 100644
--- a/test/files/neg/t5692a/Test_2.scala
+++ b/test/files/pos/t5692a/Test_2.scala
diff --git a/test/files/neg/t5692b.check b/test/files/pos/t5692b.check
index 16796826b4..16796826b4 100644
--- a/test/files/neg/t5692b.check
+++ b/test/files/pos/t5692b.check
diff --git a/test/files/neg/t5692b.flags b/test/files/pos/t5692b.flags
index cd66464f2f..cd66464f2f 100644
--- a/test/files/neg/t5692b.flags
+++ b/test/files/pos/t5692b.flags
diff --git a/test/files/neg/t5692b/Macros_1.scala b/test/files/pos/t5692b/Macros_1.scala
index b28d19f903..b28d19f903 100644
--- a/test/files/neg/t5692b/Macros_1.scala
+++ b/test/files/pos/t5692b/Macros_1.scala
diff --git a/test/files/neg/t5692b/Test_2.scala b/test/files/pos/t5692b/Test_2.scala
index 08d510cc6f..08d510cc6f 100644
--- a/test/files/neg/t5692b/Test_2.scala
+++ b/test/files/pos/t5692b/Test_2.scala
diff --git a/test/files/pos/t5692c.check b/test/files/pos/t5692c.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/pos/t5692c.check
diff --git a/test/files/pos/t5692c.scala b/test/files/pos/t5692c.scala
new file mode 100644
index 0000000000..fa5f0b2dcd
--- /dev/null
+++ b/test/files/pos/t5692c.scala
@@ -0,0 +1,4 @@
+class C {
+ def foo[T: scala.reflect.ClassTag](xs: T*): Array[T] = ???
+ foo()
+} \ No newline at end of file
diff --git a/test/files/run/macro-divergence-spurious.check b/test/files/run/macro-divergence-spurious.check
new file mode 100644
index 0000000000..19765bd501
--- /dev/null
+++ b/test/files/run/macro-divergence-spurious.check
@@ -0,0 +1 @@
+null
diff --git a/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala
new file mode 100644
index 0000000000..bc4a9fded7
--- /dev/null
+++ b/test/files/run/macro-divergence-spurious/Impls_Macros_1.scala
@@ -0,0 +1,23 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+trait Complex[T]
+
+class Foo(val bar: Bar)
+class Bar(val s: String)
+
+object Complex {
+ def impl[T: c.WeakTypeTag](c: Context): c.Expr[Complex[T]] = {
+ import c.universe._
+ val tpe = weakTypeOf[T]
+ for (f <- tpe.declarations.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) {
+ val trecur = appliedType(typeOf[Complex[_]], List(f.typeSignature))
+ val recur = c.inferImplicitValue(trecur, silent = true)
+ if (recur == EmptyTree) c.abort(c.enclosingPosition, s"couldn't synthesize $trecur")
+ }
+ c.literalNull
+ }
+
+ implicit object ComplexString extends Complex[String]
+ implicit def genComplex[T]: Complex[T] = macro impl[T]
+}
diff --git a/test/files/run/macro-divergence-spurious/Test_2.scala b/test/files/run/macro-divergence-spurious/Test_2.scala
new file mode 100644
index 0000000000..dcc4593335
--- /dev/null
+++ b/test/files/run/macro-divergence-spurious/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ println(implicitly[Complex[Foo]])
+} \ No newline at end of file
diff --git a/test/files/run/t5923a.check b/test/files/run/t5923a.check
new file mode 100644
index 0000000000..7165b734ac
--- /dev/null
+++ b/test/files/run/t5923a.check
@@ -0,0 +1,3 @@
+C(Int)
+C(String)
+C(Nothing)
diff --git a/test/files/run/t5923a/Macros_1.scala b/test/files/run/t5923a/Macros_1.scala
new file mode 100644
index 0000000000..6d21362c4d
--- /dev/null
+++ b/test/files/run/t5923a/Macros_1.scala
@@ -0,0 +1,14 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+case class C[T](t: String)
+object C {
+ implicit def foo[T]: C[T] = macro Macros.impl[T]
+}
+
+object Macros {
+ def impl[T: c.WeakTypeTag](c: Context) = {
+ import c.universe._
+ reify(C[T](c.literal(weakTypeOf[T].toString).splice))
+ }
+} \ No newline at end of file
diff --git a/test/files/run/t5923a/Test_2.scala b/test/files/run/t5923a/Test_2.scala
new file mode 100644
index 0000000000..001ff9aea8
--- /dev/null
+++ b/test/files/run/t5923a/Test_2.scala
@@ -0,0 +1,5 @@
+object Test extends App {
+ println(implicitly[C[Int]])
+ println(implicitly[C[String]])
+ println(implicitly[C[Nothing]])
+} \ No newline at end of file
diff --git a/test/files/run/t5923b.check b/test/files/run/t5923b.check
new file mode 100644
index 0000000000..d56076f84e
--- /dev/null
+++ b/test/files/run/t5923b.check
@@ -0,0 +1,3 @@
+class [Ljava.lang.Object;
+class [Ljava.lang.Object;
+class [Ljava.lang.Object;
diff --git a/test/files/run/t5923b/Test.scala b/test/files/run/t5923b/Test.scala
new file mode 100644
index 0000000000..7c2627462a
--- /dev/null
+++ b/test/files/run/t5923b/Test.scala
@@ -0,0 +1,7 @@
+object Test extends App {
+ import scala.collection.generic.CanBuildFrom
+ val cbf = implicitly[CanBuildFrom[Nothing, Nothing, Array[Nothing]]]
+ println(cbf().result.getClass)
+ println(new Array[Nothing](0).getClass)
+ println(Array[Nothing]().getClass)
+} \ No newline at end of file
diff --git a/test/files/run/t7047.check b/test/files/run/t7047.check
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/run/t7047.check
diff --git a/test/files/run/t7047/Impls_Macros_1.scala b/test/files/run/t7047/Impls_Macros_1.scala
new file mode 100644
index 0000000000..2992e3efe4
--- /dev/null
+++ b/test/files/run/t7047/Impls_Macros_1.scala
@@ -0,0 +1,19 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+class Foo
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ try {
+ c.inferImplicitValue(typeOf[Foo], silent = false)
+ c.abort(c.enclosingPosition, "silent=false is not working")
+ } catch {
+ case _: Exception =>
+ }
+ c.literalNull
+ }
+
+ def foo = macro impl
+} \ No newline at end of file
diff --git a/test/files/run/t7047/Test_2.scala b/test/files/run/t7047/Test_2.scala
new file mode 100644
index 0000000000..acfddae942
--- /dev/null
+++ b/test/files/run/t7047/Test_2.scala
@@ -0,0 +1,3 @@
+object Test extends App {
+ Macros.foo
+} \ No newline at end of file
diff --git a/test/files/run/t7291a.check b/test/files/run/t7291a.check
new file mode 100644
index 0000000000..126faa15b4
--- /dev/null
+++ b/test/files/run/t7291a.check
@@ -0,0 +1 @@
+conjure
diff --git a/test/files/run/t7291a.flags b/test/files/run/t7291a.flags
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/files/run/t7291a.flags
diff --git a/test/files/run/t7291a.scala b/test/files/run/t7291a.scala
new file mode 100644
index 0000000000..4b7c4a4184
--- /dev/null
+++ b/test/files/run/t7291a.scala
@@ -0,0 +1,19 @@
+trait Fooable[T]
+object Fooable {
+ implicit def conjure[T]: Fooable[T] = {
+ println("conjure")
+ new Fooable[T]{}
+ }
+
+}
+
+object Test {
+ implicit def traversable[T, Coll[_] <: Traversable[_]](implicit
+elem: Fooable[T]): Fooable[Coll[T]] = {
+ println("traversable")
+ new Fooable[Coll[T]]{}
+ }
+ def main(args: Array[String]) {
+ implicitly[Fooable[List[Any]]]
+ }
+}
diff --git a/test/files/run/t7291b.check b/test/files/run/t7291b.check
new file mode 100644
index 0000000000..c07ba986a3
--- /dev/null
+++ b/test/files/run/t7291b.check
@@ -0,0 +1,2 @@
+conjure
+traversable
diff --git a/test/files/run/t7291b.flags b/test/files/run/t7291b.flags
new file mode 100644
index 0000000000..d564f2b1f8
--- /dev/null
+++ b/test/files/run/t7291b.flags
@@ -0,0 +1 @@
+-Xdivergence211 \ No newline at end of file
diff --git a/test/files/run/t7291b.scala b/test/files/run/t7291b.scala
new file mode 100644
index 0000000000..30c4261a81
--- /dev/null
+++ b/test/files/run/t7291b.scala
@@ -0,0 +1,19 @@
+trait Fooable[T]
+object Fooable {
+ implicit def conjure[T]: Fooable[T] = {
+ println("conjure")
+ new Fooable[T]{}
+ }
+
+}
+
+object Test {
+ implicit def traversable[T, Coll[_] <: Traversable[_]](implicit
+elem: Fooable[T]): Fooable[Coll[T]] = {
+ println("traversable")
+ new Fooable[Coll[T]]{}
+ }
+ def main(args: Array[String]) {
+ implicitly[Fooable[List[Any]]]
+ }
+}