diff options
Diffstat (limited to 'test')
43 files changed, 250 insertions, 1 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/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/macro-system-properties.check b/test/files/run/macro-system-properties.check new file mode 100644 index 0000000000..dce976df02 --- /dev/null +++ b/test/files/run/macro-system-properties.check @@ -0,0 +1,26 @@ +Type in expressions to have them evaluated. +Type :help for more information. + +scala> + +scala> import language.experimental._, reflect.macros.Context +import language.experimental._ +import reflect.macros.Context + +scala> object GrabContext { + def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) + // System.properties lets you stash true globals (unlike statics which are classloader scoped) + def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit } + def grab() = macro impl + } +defined module GrabContext + +scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +defined module Test + +scala> object Test { class C(implicit a: Any) { GrabContext.grab } } +defined module Test + +scala> + +scala> diff --git a/test/files/run/macro-system-properties.scala b/test/files/run/macro-system-properties.scala new file mode 100644 index 0000000000..e182defc81 --- /dev/null +++ b/test/files/run/macro-system-properties.scala @@ -0,0 +1,16 @@ +import scala.tools.nsc._ +import scala.tools.partest.ReplTest + +object Test extends ReplTest { + def code = """ + import language.experimental._, reflect.macros.Context + object GrabContext { + def lastContext = Option(System.getProperties.get("lastContext").asInstanceOf[reflect.macros.runtime.Context]) + // System.properties lets you stash true globals (unlike statics which are classloader scoped) + def impl(c: Context)() = { System.getProperties.put("lastContext", c); c.literalUnit } + def grab() = macro impl + } + object Test { class C(implicit a: Any) { GrabContext.grab } } + object Test { class C(implicit a: Any) { GrabContext.grab } } + """ +} 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]]] + } +} diff --git a/test/files/neg/t5353.check b/test/pending/neg/t5353.check index 75e2435600..75e2435600 100644 --- a/test/files/neg/t5353.check +++ b/test/pending/neg/t5353.check diff --git a/test/files/neg/t5353.scala b/test/pending/neg/t5353.scala index 1ee869aac1..1ee869aac1 100644 --- a/test/files/neg/t5353.scala +++ b/test/pending/neg/t5353.scala |