From d51d08b444e0ea4a2c13b4daf0ce14b53bfbad89 Mon Sep 17 00:00:00 2001 From: Samuel Gruetter Date: Wed, 19 Mar 2014 17:53:49 +0100 Subject: move all tests in tests/untried/neg which use implicits to tests/untried/neg-with-implicits --- .../classmanifests_new_deprecations.scala | 37 ++++++ .../neg-with-implicits/compile-time-only-a.scala | 76 +++++++++++ .../neg-with-implicits/divergent-implicit.scala | 16 +++ .../neg-with-implicits/forgot-interpolator.scala | 93 ++++++++++++++ .../neg-with-implicits/implicit-shadow.scala | 13 ++ tests/untried/neg-with-implicits/implicits.scala | 74 +++++++++++ .../untried/neg-with-implicits/logImplicits.scala | 25 ++++ .../Macros_1.scala | 25 ++++ .../Test_2.scala | 4 + .../Macros_1.scala | 39 ++++++ .../Test_2.scala | 12 ++ .../macro-bundle-whitebox-use-raw/Macros_1.scala | 108 ++++++++++++++++ .../macro-bundle-whitebox-use-raw/Test_2.scala | 19 +++ .../Macros_1.scala | 108 ++++++++++++++++ .../macro-bundle-whitebox-use-refined/Test_2.scala | 19 +++ .../macro-cyclic/Impls_Macros_1.scala | 25 ++++ .../Impls_Macros_1.scala | 23 ++++ .../macro-divergence-controlled/Test_2.scala | 3 + .../macro-invalidsig/Impls_1.scala | 86 +++++++++++++ .../macro-invalidsig/Macros_Test_2.scala | 83 ++++++++++++ .../neg-with-implicits/overloaded-implicit.scala | 17 +++ .../patmat-classtag-compound.scala | 17 +++ .../neg-with-implicits/sammy_restrictions.scala | 45 +++++++ tests/untried/neg-with-implicits/sensitive2.scala | 8 ++ .../stringinterpolation_macro-neg.scala | 76 +++++++++++ tests/untried/neg-with-implicits/t0226.scala | 9 ++ tests/untried/neg-with-implicits/t0590.scala | 3 + tests/untried/neg-with-implicits/t1038.scala | 8 ++ tests/untried/neg-with-implicits/t2206.scala | 15 +++ tests/untried/neg-with-implicits/t2316.scala | 43 +++++++ tests/untried/neg-with-implicits/t2405.scala | 10 ++ tests/untried/neg-with-implicits/t2421b.scala | 17 +++ tests/untried/neg-with-implicits/t3006.scala | 10 ++ tests/untried/neg-with-implicits/t3224.scala | 50 ++++++++ tests/untried/neg-with-implicits/t3346b.scala | 15 +++ tests/untried/neg-with-implicits/t3346c.scala | 61 +++++++++ tests/untried/neg-with-implicits/t3346i.scala | 30 +++++ tests/untried/neg-with-implicits/t3453.scala | 66 ++++++++++ tests/untried/neg-with-implicits/t3653.scala | 4 + tests/untried/neg-with-implicits/t3692-new.scala | 20 +++ tests/untried/neg-with-implicits/t3776.scala | 10 ++ tests/untried/neg-with-implicits/t3854.scala | 15 +++ tests/untried/neg-with-implicits/t3977.scala | 13 ++ tests/untried/neg-with-implicits/t3995.scala | 32 +++++ .../untried/neg-with-implicits/t4079/t4079_1.scala | 33 +++++ .../untried/neg-with-implicits/t4079/t4079_2.scala | 3 + tests/untried/neg-with-implicits/t4270.scala | 6 + tests/untried/neg-with-implicits/t4271.scala | 12 ++ tests/untried/neg-with-implicits/t4457_1.scala | 33 +++++ tests/untried/neg-with-implicits/t4457_2.scala | 33 +++++ tests/untried/neg-with-implicits/t4568.scala | 13 ++ tests/untried/neg-with-implicits/t4882.scala | 3 + tests/untried/neg-with-implicits/t5318.scala | 8 ++ tests/untried/neg-with-implicits/t5318b.scala | 8 ++ tests/untried/neg-with-implicits/t5318c.scala | 14 +++ tests/untried/neg-with-implicits/t5340.scala | 29 +++++ tests/untried/neg-with-implicits/t5354.scala | 15 +++ tests/untried/neg-with-implicits/t5376.scala | 24 ++++ tests/untried/neg-with-implicits/t550.scala | 9 ++ tests/untried/neg-with-implicits/t5553_2.scala | 59 +++++++++ tests/untried/neg-with-implicits/t5554.scala | 39 ++++++ tests/untried/neg-with-implicits/t5578.scala | 39 ++++++ tests/untried/neg-with-implicits/t5728.scala | 7 ++ tests/untried/neg-with-implicits/t5801.scala | 16 +++ tests/untried/neg-with-implicits/t5803.scala | 4 + tests/untried/neg-with-implicits/t5839.scala | 7 ++ tests/untried/neg-with-implicits/t5892.scala | 25 ++++ .../neg-with-implicits/t5903a/Macros_1.scala | 28 +++++ .../untried/neg-with-implicits/t5903a/Test_2.scala | 6 + .../neg-with-implicits/t5903b/Macros_1.scala | 23 ++++ .../untried/neg-with-implicits/t5903b/Test_2.scala | 6 + .../neg-with-implicits/t5903c/Macros_1.scala | 26 ++++ .../untried/neg-with-implicits/t5903c/Test_2.scala | 6 + .../neg-with-implicits/t5903d/Macros_1.scala | 23 ++++ .../untried/neg-with-implicits/t5903d/Test_2.scala | 6 + .../neg-with-implicits/t5903e/Macros_1.scala | 25 ++++ .../untried/neg-with-implicits/t5903e/Test_2.scala | 6 + tests/untried/neg-with-implicits/t591.scala | 41 ++++++ tests/untried/neg-with-implicits/t6074.scala | 6 + tests/untried/neg-with-implicits/t6083.scala | 7 ++ tests/untried/neg-with-implicits/t6120.scala | 7 ++ tests/untried/neg-with-implicits/t6227.scala | 6 + tests/untried/neg-with-implicits/t6263.scala | 6 + tests/untried/neg-with-implicits/t631.scala | 3 + tests/untried/neg-with-implicits/t6335.scala | 7 ++ tests/untried/neg-with-implicits/t6436.scala | 9 ++ tests/untried/neg-with-implicits/t6436b.scala | 9 ++ tests/untried/neg-with-implicits/t6567.scala | 11 ++ tests/untried/neg-with-implicits/t6597.scala | 5 + tests/untried/neg-with-implicits/t6666d.scala | 18 +++ tests/untried/neg-with-implicits/t6667.scala | 10 ++ tests/untried/neg-with-implicits/t6667b.scala | 25 ++++ tests/untried/neg-with-implicits/t6889.scala | 18 +++ tests/untried/neg-with-implicits/t692.scala | 20 +++ .../neg-with-implicits/t6931/Macros_1.scala | 15 +++ .../untried/neg-with-implicits/t6931/Test_2.scala | 4 + tests/untried/neg-with-implicits/t696.scala | 7 ++ tests/untried/neg-with-implicits/t712.scala | 19 +++ tests/untried/neg-with-implicits/t7289.scala | 39 ++++++ .../neg-with-implicits/t7289_status_quo.scala | 23 ++++ tests/untried/neg-with-implicits/t729.scala | 23 ++++ tests/untried/neg-with-implicits/t7509.scala | 4 + .../untried/neg-with-implicits/t7519-b/Mac_1.scala | 14 +++ .../untried/neg-with-implicits/t7519-b/Use_2.scala | 10 ++ tests/untried/neg-with-implicits/t7519.scala | 18 +++ tests/untried/neg-with-implicits/t7721.scala | 140 +++++++++++++++++++++ tests/untried/neg-with-implicits/t8024.scala | 14 +++ tests/untried/neg-with-implicits/t8024b.scala | 17 +++ .../neg-with-implicits/t8104/Macros_1.scala | 11 ++ .../untried/neg-with-implicits/t8104/Test_2.scala | 21 ++++ tests/untried/neg-with-implicits/t8372.scala | 10 ++ tests/untried/neg-with-implicits/viewtest.scala | 116 +++++++++++++++++ .../neg-with-implicits/warn-unused-imports.scala | 125 ++++++++++++++++++ 113 files changed, 2914 insertions(+) create mode 100644 tests/untried/neg-with-implicits/classmanifests_new_deprecations.scala create mode 100644 tests/untried/neg-with-implicits/compile-time-only-a.scala create mode 100644 tests/untried/neg-with-implicits/divergent-implicit.scala create mode 100644 tests/untried/neg-with-implicits/forgot-interpolator.scala create mode 100644 tests/untried/neg-with-implicits/implicit-shadow.scala create mode 100644 tests/untried/neg-with-implicits/implicits.scala create mode 100644 tests/untried/neg-with-implicits/logImplicits.scala create mode 100644 tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/macro-cyclic/Impls_Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-divergence-controlled/Impls_Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-divergence-controlled/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/macro-invalidsig/Impls_1.scala create mode 100644 tests/untried/neg-with-implicits/macro-invalidsig/Macros_Test_2.scala create mode 100644 tests/untried/neg-with-implicits/overloaded-implicit.scala create mode 100644 tests/untried/neg-with-implicits/patmat-classtag-compound.scala create mode 100644 tests/untried/neg-with-implicits/sammy_restrictions.scala create mode 100644 tests/untried/neg-with-implicits/sensitive2.scala create mode 100644 tests/untried/neg-with-implicits/stringinterpolation_macro-neg.scala create mode 100644 tests/untried/neg-with-implicits/t0226.scala create mode 100644 tests/untried/neg-with-implicits/t0590.scala create mode 100644 tests/untried/neg-with-implicits/t1038.scala create mode 100644 tests/untried/neg-with-implicits/t2206.scala create mode 100644 tests/untried/neg-with-implicits/t2316.scala create mode 100644 tests/untried/neg-with-implicits/t2405.scala create mode 100644 tests/untried/neg-with-implicits/t2421b.scala create mode 100755 tests/untried/neg-with-implicits/t3006.scala create mode 100755 tests/untried/neg-with-implicits/t3224.scala create mode 100644 tests/untried/neg-with-implicits/t3346b.scala create mode 100644 tests/untried/neg-with-implicits/t3346c.scala create mode 100644 tests/untried/neg-with-implicits/t3346i.scala create mode 100644 tests/untried/neg-with-implicits/t3453.scala create mode 100644 tests/untried/neg-with-implicits/t3653.scala create mode 100644 tests/untried/neg-with-implicits/t3692-new.scala create mode 100644 tests/untried/neg-with-implicits/t3776.scala create mode 100644 tests/untried/neg-with-implicits/t3854.scala create mode 100644 tests/untried/neg-with-implicits/t3977.scala create mode 100644 tests/untried/neg-with-implicits/t3995.scala create mode 100644 tests/untried/neg-with-implicits/t4079/t4079_1.scala create mode 100644 tests/untried/neg-with-implicits/t4079/t4079_2.scala create mode 100644 tests/untried/neg-with-implicits/t4270.scala create mode 100644 tests/untried/neg-with-implicits/t4271.scala create mode 100644 tests/untried/neg-with-implicits/t4457_1.scala create mode 100644 tests/untried/neg-with-implicits/t4457_2.scala create mode 100644 tests/untried/neg-with-implicits/t4568.scala create mode 100644 tests/untried/neg-with-implicits/t4882.scala create mode 100644 tests/untried/neg-with-implicits/t5318.scala create mode 100644 tests/untried/neg-with-implicits/t5318b.scala create mode 100644 tests/untried/neg-with-implicits/t5318c.scala create mode 100644 tests/untried/neg-with-implicits/t5340.scala create mode 100644 tests/untried/neg-with-implicits/t5354.scala create mode 100644 tests/untried/neg-with-implicits/t5376.scala create mode 100644 tests/untried/neg-with-implicits/t550.scala create mode 100644 tests/untried/neg-with-implicits/t5553_2.scala create mode 100644 tests/untried/neg-with-implicits/t5554.scala create mode 100644 tests/untried/neg-with-implicits/t5578.scala create mode 100644 tests/untried/neg-with-implicits/t5728.scala create mode 100644 tests/untried/neg-with-implicits/t5801.scala create mode 100644 tests/untried/neg-with-implicits/t5803.scala create mode 100644 tests/untried/neg-with-implicits/t5839.scala create mode 100644 tests/untried/neg-with-implicits/t5892.scala create mode 100644 tests/untried/neg-with-implicits/t5903a/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t5903a/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t5903b/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t5903b/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t5903c/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t5903c/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t5903d/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t5903d/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t5903e/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t5903e/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t591.scala create mode 100644 tests/untried/neg-with-implicits/t6074.scala create mode 100644 tests/untried/neg-with-implicits/t6083.scala create mode 100644 tests/untried/neg-with-implicits/t6120.scala create mode 100644 tests/untried/neg-with-implicits/t6227.scala create mode 100644 tests/untried/neg-with-implicits/t6263.scala create mode 100644 tests/untried/neg-with-implicits/t631.scala create mode 100644 tests/untried/neg-with-implicits/t6335.scala create mode 100644 tests/untried/neg-with-implicits/t6436.scala create mode 100644 tests/untried/neg-with-implicits/t6436b.scala create mode 100644 tests/untried/neg-with-implicits/t6567.scala create mode 100644 tests/untried/neg-with-implicits/t6597.scala create mode 100644 tests/untried/neg-with-implicits/t6666d.scala create mode 100644 tests/untried/neg-with-implicits/t6667.scala create mode 100644 tests/untried/neg-with-implicits/t6667b.scala create mode 100644 tests/untried/neg-with-implicits/t6889.scala create mode 100644 tests/untried/neg-with-implicits/t692.scala create mode 100644 tests/untried/neg-with-implicits/t6931/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t6931/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t696.scala create mode 100644 tests/untried/neg-with-implicits/t712.scala create mode 100644 tests/untried/neg-with-implicits/t7289.scala create mode 100644 tests/untried/neg-with-implicits/t7289_status_quo.scala create mode 100644 tests/untried/neg-with-implicits/t729.scala create mode 100644 tests/untried/neg-with-implicits/t7509.scala create mode 100644 tests/untried/neg-with-implicits/t7519-b/Mac_1.scala create mode 100644 tests/untried/neg-with-implicits/t7519-b/Use_2.scala create mode 100644 tests/untried/neg-with-implicits/t7519.scala create mode 100644 tests/untried/neg-with-implicits/t7721.scala create mode 100644 tests/untried/neg-with-implicits/t8024.scala create mode 100644 tests/untried/neg-with-implicits/t8024b.scala create mode 100644 tests/untried/neg-with-implicits/t8104/Macros_1.scala create mode 100644 tests/untried/neg-with-implicits/t8104/Test_2.scala create mode 100644 tests/untried/neg-with-implicits/t8372.scala create mode 100644 tests/untried/neg-with-implicits/viewtest.scala create mode 100644 tests/untried/neg-with-implicits/warn-unused-imports.scala (limited to 'tests/untried/neg-with-implicits') diff --git a/tests/untried/neg-with-implicits/classmanifests_new_deprecations.scala b/tests/untried/neg-with-implicits/classmanifests_new_deprecations.scala new file mode 100644 index 000000000..7aebf011f --- /dev/null +++ b/tests/untried/neg-with-implicits/classmanifests_new_deprecations.scala @@ -0,0 +1,37 @@ +object Test extends App { + def cm1[T: ClassManifest] = ??? + def cm2[T](implicit evidence$1: ClassManifest[T]) = ??? + val cm3: ClassManifest[Int] = null + + def rcm1[T: scala.reflect.ClassManifest] = ??? + def rcm2[T](implicit evidence$1: scala.reflect.ClassManifest[T]) = ??? + val rcm3: scala.reflect.ClassManifest[Int] = null + + type CM[T] = ClassManifest[T] + def acm1[T: CM] = ??? + def acm2[T](implicit evidence$1: CM[T]) = ??? + val acm3: CM[Int] = null + + type RCM[T] = scala.reflect.ClassManifest[T] + def arcm1[T: RCM] = ??? + def arcm2[T](implicit evidence$1: RCM[T]) = ??? + val arcm3: RCM[Int] = null + + def m1[T: Manifest] = ??? + def m2[T](implicit evidence$1: Manifest[T]) = ??? + val m3: Manifest[Int] = null + + def rm1[T: scala.reflect.Manifest] = ??? + def rm2[T](implicit evidence$1: scala.reflect.Manifest[T]) = ??? + val rm3: scala.reflect.Manifest[Int] = null + + type M[T] = Manifest[T] + def am1[T: M] = ??? + def am2[T](implicit evidence$1: M[T]) = ??? + val am3: M[Int] = null + + type RM[T] = scala.reflect.Manifest[T] + def arm1[T: RM] = ??? + def arm2[T](implicit evidence$1: RM[T]) = ??? + val arm3: RM[Int] = null +} diff --git a/tests/untried/neg-with-implicits/compile-time-only-a.scala b/tests/untried/neg-with-implicits/compile-time-only-a.scala new file mode 100644 index 000000000..130a3c539 --- /dev/null +++ b/tests/untried/neg-with-implicits/compile-time-only-a.scala @@ -0,0 +1,76 @@ +import scala.annotation.compileTimeOnly +import scala.language.existentials + +@compileTimeOnly("C1") class C1 +object C1 + +class C2 +@compileTimeOnly("C2") object C2 + +@compileTimeOnly("C3") case class C3(x: Int) + +@compileTimeOnly("C4") case class C4(x: Int) +object C4 + +object pkg { + @compileTimeOnly("C5") + implicit class C5(val x: Int) { + def ext = ??? + } +} + +class C6(@compileTimeOnly("C6.x") val x: Int) { + @compileTimeOnly("C6.foo") def foo = 2 + @compileTimeOnly("C6.Foo") type Foo = Int + @compileTimeOnly("C6.y") var y = 3 +} + +@compileTimeOnly("C7") class C7 +@compileTimeOnly("C8") class C8[T] + +object Test extends App { + new C1() + C1 + + new C2() + C2 + + new C3(2) + C3(2) + + new C4(2) + C4(2) + + import pkg._ + 2.ext + C5(2) + + val c6 = new C6(2) + val _ = c6.x + c6.foo + type Foo = c6.Foo + c6.y = c6.y + + val c701: (C7, C7) = ??? + val c702: (C7 => C7) = ??? + val c703: { val x: C7 } = ??? + val c704: AnyRef with C7 = ??? + // https://groups.google.com/forum/#!topic/scala-internals/5n07TiCnBZU + // val c705: ({ @compileTimeOnly("C7") type C7[T] = List[T] })#C7[_] = ??? + val c706: C7 Either C7 = ??? + val c707a: List[C7] = ??? + val c707b = List[C7]() + val c708a: T forSome { type T <: C7 } = ??? + // https://groups.google.com/forum/#!topic/scala-internals/5n07TiCnBZU + // val c708b: T forSome { @compileTimeOnly("C7") type T } = ??? + val c709: (C8[Int], C8[C7]) = ??? + val c710: (C8[_] => C8[_]) = ??? +} + +@compileTimeOnly("placebo") +class placebo extends scala.annotation.StaticAnnotation + +@placebo +class Test { + @placebo def x = (2: @placebo) +} diff --git a/tests/untried/neg-with-implicits/divergent-implicit.scala b/tests/untried/neg-with-implicits/divergent-implicit.scala new file mode 100644 index 000000000..4a356d54f --- /dev/null +++ b/tests/untried/neg-with-implicits/divergent-implicit.scala @@ -0,0 +1,16 @@ +object Test1 { + implicit def cast[A, B](x: A)(implicit c: A => B): B = c(x) + + val x1: String = 1 + val x2: String = cast[Int, String](1) +} +object Test2 { + class Foo + class Bar + class Baz + implicit def foo2bar(x: Foo)(implicit baz2bar: Baz => Bar): Bar = baz2bar(new Baz) + implicit def baz2bar(x: Baz)(implicit foo2bar: Foo => Bar): Bar = foo2bar(new Foo) + + val x: Bar = new Foo + val y: Bar = new Baz +} diff --git a/tests/untried/neg-with-implicits/forgot-interpolator.scala b/tests/untried/neg-with-implicits/forgot-interpolator.scala new file mode 100644 index 000000000..a53054d89 --- /dev/null +++ b/tests/untried/neg-with-implicits/forgot-interpolator.scala @@ -0,0 +1,93 @@ +class A { + val bippy = 123 + + def f = "Put the $bippy in the $bippy!" // warn 1 +} + +class B { + val dingus = 123 + + def f = "Put the $bippy in the $bippy!" // no warn +} + +class C { + def f = """Put the ${println("bippy")} in the bippy!""" // warn 2 +} + +package object test { + def aleppo = 9 + def greppo(n: Int) = ??? + def zappos(n: Int)(implicit ord: math.Ordering[Int]) = ??? + def hippo(implicit n: Int) = ??? +} + +package test { + // not sure if overloading is kosher in pkg obj yet + class Doo { + def beppo(i: Int) = 8 * i + def beppo = 8 + class Dah extends Doo { + def f = "$beppo was a marx bros who saw dollars." // warn 3 + } + } + class E { + def f = "$aleppo is a pepper and a city." // warn 4 + def k = s"Just an interpolation of $aleppo" // no warn + } + class Bar { + private def bar = 8 + if (bar > 8) ??? // use it to avoid extra warning + } + class Baz extends Bar { + def f = "$bar is private, shall we warn just in case?" // no longer a warning, private members aren't inherited! + } + class G { + def g = "$greppo takes an arg" // no warn + def z = "$zappos takes an arg too" // no warn + def h = "$hippo takes an implicit" // warn 6 + } + class J { + def j = 8 + class J2 { + def j(i: Int) = 2 * i + def jj = "shadowed $j" // no warn + } + } + import annotation._ + @implicitNotFound("No Z in ${A}") // no warn + class Z[A] +} + + +package inf1 { + import scala.annotation.implicitNotFound + + @implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") // no warn + trait CannotBuildFrom[-From, -Elem, +To] +} + +package inf2 { + @scala.annotation.implicitNotFound(msg = "Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") // no warn + trait CannotBuildFrom[-From, -Elem, +To] +} + +package inf3 { + @scala.annotation.implicitNotFound("Cannot construct a collection of type ${To} with elements of type ${Elem} based on a collection of type ${From}.") // no warn + trait CannotBuildFrom[-From, -Elem, +To] +} + +package curry { + class A { + def bunko()(x: Int): Int = 5 + def groucho(): Int = 5 + def dingo()()()()()(): Int = 5 // kind of nuts this can be evaluated with just 'dingo', but okay + def calico[T1, T2]()()(): Int = 5 // even nutsier + def palomino[T1, T2]()(y: Int = 5)(): Int = 5 // even nutsier + + def f1 = "I was picked up by the $bunko squad" // no warn + def f2 = "I salute $groucho" // warn 7 + def f3 = "I even salute $dingo" // warn 8 + def f4 = "I also salute $calico" // warn 9 + def f5 = "I draw the line at $palomino" // no warn + } +} diff --git a/tests/untried/neg-with-implicits/implicit-shadow.scala b/tests/untried/neg-with-implicits/implicit-shadow.scala new file mode 100644 index 000000000..ec7f70b6d --- /dev/null +++ b/tests/untried/neg-with-implicits/implicit-shadow.scala @@ -0,0 +1,13 @@ +object Test { + import B._, C._ + + 1.isEmpty +} + +trait A { + implicit def i2s(i: Int): String = "" +} + +object B extends A + +object C extends A diff --git a/tests/untried/neg-with-implicits/implicits.scala b/tests/untried/neg-with-implicits/implicits.scala new file mode 100644 index 000000000..22633a1f3 --- /dev/null +++ b/tests/untried/neg-with-implicits/implicits.scala @@ -0,0 +1,74 @@ +class Pos + +class Super + +object Super { + implicit def pos2int(p: Pos): Int = 0 +} + +object Sub extends Super { + class Plus(x: Any) { + def +(y: String): String = x.toString + y + } + implicit def any2plus(x: Any): Plus = new Plus(x) +} + +object Test { + import Super._ + import Sub._ + val p = new Pos + def f(x: Int): Int = x + f(p+1) +} + +object test2 { + sealed trait HMap { + def +[T](v: T) = HSome(v,this) + } + + final case class HSome[T, L <: HMap](head: T, tail: L) extends HMap + + final object HEmpty extends HMap + + val set = HEmpty + 3 + "3" + implicit def select[T](t: HSome[T,_]) = t.head + implicit def selectTail[L](t: HSome[_,L]) = t.tail + + def foo(x: Int) = 3 + foo(set) +} + +// #2180 +class Mxml { + + private def processChildren( children:Seq[Any] ):List[Mxml] = { + + children.toList.flatMap ( e => { + + e match { + + case s:scala.collection.Traversable[_] => s case a => List(a) + + } + + }) + + } + +} + +// SI-5316 +class Test3 { + def foo(p: => Any)(implicit x: Nothing): Unit = () + + object X + + foo { + val a = 0 + + { + import X._ + a + } + } +} diff --git a/tests/untried/neg-with-implicits/logImplicits.scala b/tests/untried/neg-with-implicits/logImplicits.scala new file mode 100644 index 000000000..ecb4cbb31 --- /dev/null +++ b/tests/untried/neg-with-implicits/logImplicits.scala @@ -0,0 +1,25 @@ +class A { + def f(xs: Array[Byte]) = xs.size + def g(xs: Array[Byte]) = xs.length +} + +class B { + def f = "abc" map (_ + 1) +} + +object C { + final val x = "abc" + + implicit def convert(p: x.type): Int = 123 + + math.max(122, x: Int) +} + +class D { + def f = (1 -> 2) + "c" +} + +class Un { + // forcing post-typer failure, since we're only interested in the output from the above + def unimplemented: Int +} diff --git a/tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Macros_1.scala b/tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Macros_1.scala new file mode 100644 index 000000000..16a379ea5 --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +trait Foo[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: Foo[T] = null +} + +object Foo extends LowPriority { + implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] +} + +object Macros { + def impl[T: c.WeakTypeTag](c: Context) = { + import c.universe._ + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.info =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" + } +} diff --git a/tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Test_2.scala b/tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Test_2.scala new file mode 100644 index 000000000..abb5229bd --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-blackbox-dynamic-materialization/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + println(implicitly[Foo[C1]]) + println(implicitly[Foo[C2]]) +} diff --git a/tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Macros_1.scala b/tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Macros_1.scala new file mode 100644 index 000000000..8d776388e --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Macros_1.scala @@ -0,0 +1,39 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +trait Iso[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +object Iso { + implicit def materializeIso[T, U]: Iso[T, U] = macro impl[T, U] + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag](c: Context): c.Expr[Iso[T, U]] = { + import c.universe._ + import definitions._ + import Flag._ + + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.info.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.info))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("Iso")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(typeNames.EMPTY), typeNames.EMPTY), termNames.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[Iso[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), termNames.CONSTRUCTOR), List()))) + } +} diff --git a/tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Test_2.scala b/tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Test_2.scala new file mode 100644 index 000000000..8b60943cf --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-blackbox-fundep-materialization/Test_2.scala @@ -0,0 +1,12 @@ +// see the comments for macroExpand.onDelayed for an explanation of what's tested here +object Test extends App { + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: Iso[C, L]): L = iso.to(c) + + { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T): Unit = {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } +} diff --git a/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Macros_1.scala b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Macros_1.scala new file mode 100644 index 000000000..61bf73e48 --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Macros_1.scala @@ -0,0 +1,108 @@ +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +// whitebox use case #1: return type refinement + +class ReturnTypeRefinementBundle(val c: Context) { + import c.universe._ + def impl = { + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } +} + +object ReturnTypeRefinement { + def foo: Any = macro ReturnTypeRefinementBundle.impl +} + +// whitebox use case #2: fundep materialization + +trait FundepMaterialization[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +class FundepMaterializationBundle(val c: Context) { + import c.universe._ + import definitions._ + import Flag._ + + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag]: c.Expr[FundepMaterialization[T, U]] = { + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.info.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.info))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("FundepMaterialization")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(typeNames.EMPTY), typeNames.EMPTY), termNames.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[FundepMaterialization[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), termNames.CONSTRUCTOR), List()))) + } +} + +object FundepMaterialization { + implicit def materializeIso[T, U]: FundepMaterialization[T, U] = macro FundepMaterializationBundle.impl[T, U] +} + +// whitebox use case #3: dynamic materialization + +trait DynamicMaterialization[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: DynamicMaterialization[T] = null +} + +object DynamicMaterialization extends LowPriority { + implicit def moreSpecific[T]: DynamicMaterialization[T] = macro DynamicMaterializationBundle.impl[T] +} + +class DynamicMaterializationBundle(val c: Context) { + import c.universe._ + def impl[T: c.WeakTypeTag] = { + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.info =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new DynamicMaterialization[$tpe]{ override def toString = ${tpe.toString} }" + } +} + +// whitebox use case #4: extractor macros + +object ExtractorMacro { + def unapply(x: Int): Any = macro ExtractorBundle.unapplyImpl +} + +class ExtractorBundle(val c: Context) { + import c.universe._ + def unapplyImpl(x: Tree) = { + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Test_2.scala b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Test_2.scala new file mode 100644 index 000000000..995da737c --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-raw/Test_2.scala @@ -0,0 +1,19 @@ +object Test extends App { + println(ReturnTypeRefinement.foo.x) + + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: FundepMaterialization[C, L]): L = iso.to(c) + locally { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T): Unit = {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } + + println(implicitly[DynamicMaterialization[C1]]) + println(implicitly[DynamicMaterialization[C2]]) + + 42 match { + case ExtractorMacro(x) => println(x) + } +} diff --git a/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Macros_1.scala b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Macros_1.scala new file mode 100644 index 000000000..186604422 --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Macros_1.scala @@ -0,0 +1,108 @@ +import scala.reflect.macros.blackbox.Context +import scala.language.experimental.macros + +// whitebox use case #1: return type refinement + +class ReturnTypeRefinementBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + def impl = { + q""" + trait Foo { + def x = 2 + } + new Foo {} + """ + } +} + +object ReturnTypeRefinement { + def foo: Any = macro ReturnTypeRefinementBundle.impl +} + +// whitebox use case #2: fundep materialization + +trait FundepMaterialization[T, U] { + def to(t : T) : U + // def from(u : U) : T +} + +class FundepMaterializationBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + import definitions._ + import Flag._ + + def impl[T: c.WeakTypeTag, U: c.WeakTypeTag]: c.Expr[FundepMaterialization[T, U]] = { + val sym = c.weakTypeOf[T].typeSymbol + if (!sym.isClass || !sym.asClass.isCaseClass) c.abort(c.enclosingPosition, s"$sym is not a case class") + val fields = sym.info.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + + def mkTpt() = { + val core = Ident(TupleClass(fields.length) orElse UnitClass) + if (fields.length == 0) core + else AppliedTypeTree(core, fields map (f => TypeTree(f.info))) + } + + def mkFrom() = { + if (fields.length == 0) Literal(Constant(Unit)) + else Apply(Ident(newTermName("Tuple" + fields.length)), fields map (f => Select(Ident(newTermName("f")), newTermName(f.name.toString.trim)))) + } + + val evidenceClass = ClassDef(Modifiers(FINAL), newTypeName("$anon"), List(), Template( + List(AppliedTypeTree(Ident(newTypeName("FundepMaterialization")), List(Ident(sym), mkTpt()))), + emptyValDef, + List( + DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(Apply(Select(Super(This(typeNames.EMPTY), typeNames.EMPTY), termNames.CONSTRUCTOR), List())), Literal(Constant(())))), + DefDef(Modifiers(), newTermName("to"), List(), List(List(ValDef(Modifiers(PARAM), newTermName("f"), Ident(sym), EmptyTree))), TypeTree(), mkFrom())))) + c.Expr[FundepMaterialization[T, U]](Block(List(evidenceClass), Apply(Select(New(Ident(newTypeName("$anon"))), termNames.CONSTRUCTOR), List()))) + } +} + +object FundepMaterialization { + implicit def materializeIso[T, U]: FundepMaterialization[T, U] = macro FundepMaterializationBundle.impl[T, U] +} + +// whitebox use case #3: dynamic materialization + +trait DynamicMaterialization[T] + +class C1(val x: Int) +class C2(val x: String) + +trait LowPriority { + implicit def lessSpecific[T]: DynamicMaterialization[T] = null +} + +object DynamicMaterialization extends LowPriority { + implicit def moreSpecific[T]: DynamicMaterialization[T] = macro DynamicMaterializationBundle.impl[T] +} + +class DynamicMaterializationBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + def impl[T: c.WeakTypeTag] = { + val tpe = weakTypeOf[T] + if (tpe.members.exists(_.info =:= typeOf[Int])) + c.abort(c.enclosingPosition, "I don't like classes that contain integers") + q"new DynamicMaterialization[$tpe]{ override def toString = ${tpe.toString} }" + } +} + +// whitebox use case #4: extractor macros + +object ExtractorMacro { + def unapply(x: Int): Any = macro ExtractorBundle.unapplyImpl +} + +class ExtractorBundle(val c: Context { type PrefixType = Nothing }) { + import c.universe._ + def unapplyImpl(x: Tree) = { + q""" + new { + class Match(x: Int) { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Test_2.scala b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Test_2.scala new file mode 100644 index 000000000..995da737c --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-bundle-whitebox-use-refined/Test_2.scala @@ -0,0 +1,19 @@ +object Test extends App { + println(ReturnTypeRefinement.foo.x) + + case class Foo(i: Int, s: String, b: Boolean) + def foo[C, L](c: C)(implicit iso: FundepMaterialization[C, L]): L = iso.to(c) + locally { + val equiv = foo(Foo(23, "foo", true)) + def typed[T](t: => T): Unit = {} + typed[(Int, String, Boolean)](equiv) + println(equiv) + } + + println(implicitly[DynamicMaterialization[C1]]) + println(implicitly[DynamicMaterialization[C2]]) + + 42 match { + case ExtractorMacro(x) => println(x) + } +} diff --git a/tests/untried/neg-with-implicits/macro-cyclic/Impls_Macros_1.scala b/tests/untried/neg-with-implicits/macro-cyclic/Impls_Macros_1.scala new file mode 100644 index 000000000..ad6890144 --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-cyclic/Impls_Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = { + c.universe.reify { implicitly[SourceLocation] } + } + + implicit def sourceLocation: SourceLocation1 = macro impl +} + +trait SourceLocation { + /** Source location of the outermost call */ + val outer: SourceLocation + + /** The name of the source file */ + val fileName: String + + /** The line number */ + val line: Int + + /** The character offset */ + val charOffset: Int +} + +case class SourceLocation1(val outer: SourceLocation, val fileName: String, val line: Int, val charOffset: Int) extends SourceLocation diff --git a/tests/untried/neg-with-implicits/macro-divergence-controlled/Impls_Macros_1.scala b/tests/untried/neg-with-implicits/macro-divergence-controlled/Impls_Macros_1.scala new file mode 100644 index 000000000..5c0450326 --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-divergence-controlled/Impls_Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.whitebox.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.decls.collect{case f: TermSymbol if f.isParamAccessor && !f.isMethod => f}) { + val trecur = appliedType(typeOf[Complex[_]], List(f.info)) + if (c.openImplicits.tail.exists(ic => ic.pt =:= 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.Expr[Null](q"null") + } + + implicit object ComplexString extends Complex[String] + implicit def genComplex[T]: Complex[T] = macro impl[T] +} diff --git a/tests/untried/neg-with-implicits/macro-divergence-controlled/Test_2.scala b/tests/untried/neg-with-implicits/macro-divergence-controlled/Test_2.scala new file mode 100644 index 000000000..e06175f30 --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-divergence-controlled/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + println(implicitly[Complex[Foo]]) +} diff --git a/tests/untried/neg-with-implicits/macro-invalidsig/Impls_1.scala b/tests/untried/neg-with-implicits/macro-invalidsig/Impls_1.scala new file mode 100644 index 000000000..2816c4ddf --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-invalidsig/Impls_1.scala @@ -0,0 +1,86 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.macros.blackbox.Context + +object Impls1 { + def foo[U: c.WeakTypeTag: Numeric](c: Context) = { import c.universe._; q"42" } +} + +object Impls2 { + def foo = ??? +} + +object Impls3 { + def foo(c: scala.reflect.api.Universe) = ??? +} + +object Impls4 { + def foo(cs: Context*) = ??? +} + +object Impls5 { + def foo(c: Context) = ??? +} + +object Impls6 { + def foo[T, U: c.WeakTypeTag](c: Context)(implicit x: c.Expr[Int]) = { + import c.{prefix => prefix} + import c.universe._ + c.Expr[Unit](q""" + println("invoking foo_targs...") + println("type of prefix is: " + ${prefix.staticType.toString}) + println("U is: " + ${implicitly[c.WeakTypeTag[U]].tpe.toString}) + """) + } +} + +object Impls7 { + def foo(c: Context)(x: c.Expr[Int], y: c.Expr[Int]) = ??? +} + +object Impls8 { + def foo(c: Context)(x: c.universe.Symbol) = ??? +} + +object Impls9 { + def foo(c: Context)(xs: c.Expr[Int]*) = ??? +} + +object Impls10 { + def foo(c: Context)(y: c.Expr[Int], x: c.Expr[Int]) = ??? +} + +object Impls11 { + def foo[U](c: Context)(U: c.universe.Type) = ??? +} + +object Impls12 { + def foo[U <: String](c: Context) = ??? +} + +object Impls13 { + def foo[U <: String](c: Context) = ??? +} + +object Impls14 { + def foo[U: c.WeakTypeTag](c: Context) = ??? +} + +object Impls15 { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + import c.universe._ + println(implicitly[c.WeakTypeTag[T]]) + println(implicitly[c.WeakTypeTag[U]]) + println(V) + c.Expr[Unit](q"()") + } +} + +object Impls16 { + def foo[T: c.WeakTypeTag, U: c.WeakTypeTag, V](c: Context)(implicit V: c.WeakTypeTag[V]): c.Expr[Unit] = { + import c.universe._ + println(implicitly[c.WeakTypeTag[T]]) + println(implicitly[c.WeakTypeTag[U]]) + println(V) + c.Expr[Unit](q"()") + } +} diff --git a/tests/untried/neg-with-implicits/macro-invalidsig/Macros_Test_2.scala b/tests/untried/neg-with-implicits/macro-invalidsig/Macros_Test_2.scala new file mode 100644 index 000000000..d662a029e --- /dev/null +++ b/tests/untried/neg-with-implicits/macro-invalidsig/Macros_Test_2.scala @@ -0,0 +1,83 @@ +object Macros1 { + def foo[U]: Int = macro Impls1.foo[U] +} + +object Macros2 { + def foo = macro Impls2.foo +} + +object Macros3 { + def foo = macro Impls3.foo +} + +object Macros4 { + def foo = macro Impls4.foo +} + +object Macros5 { + def foo(x: Any) = macro Impls5.foo +} + +class Macros6[T] { + def foo[U](x: Int) = macro Impls6.foo[T, U] +} + +object Macros7 { + def foo(x: Int) = macro Impls7.foo +} + +object Macros8 { + def foo(x: Int) = macro Impls8.foo +} + +object Macros9 { + def foo(x: Int, y: Int) = macro Impls9.foo +} + +object Macros10 { + def foo(x: Int, y: Int) = macro Impls10.foo +} + +object Macros11 { + def foo[U] = macro Impls11.foo[U] +} + +object Macros12 { + def foo[U] = macro Impls12.foo[U] +} + +object Macros13 { + def foo[U <: Int] = macro Impls13.foo[U] +} + +object Macros14 { + def foo = macro Impls14.foo +} + +class D[T] { + class C[U] { + def foo15[V]: Unit = macro Impls15.foo + def foo16[V]: Unit = macro Impls16.foo[V] + } +} + +object Test extends App { + println(Macros1.foo[String]) + println(Macros2.foo) + println(Macros3.foo) + println(Macros4.foo) + println(Macros5.foo(42)) + println(new Macros6[Int]().foo[String](42)) + println(Macros7.foo(42)) + println(Macros8.foo) + println(Macros9.foo(4, 2)) + println(Macros10.foo(4, 2)) + println(Macros11.foo[Int]) + println(Macros12.foo[Int]) + println(Macros13.foo[Int]) + println(Macros14.foo) + val outer1 = new D[Int] + val outer2 = new outer1.C[String] + outer2.foo15[Boolean] + outer2.foo16[Boolean] +} diff --git a/tests/untried/neg-with-implicits/overloaded-implicit.scala b/tests/untried/neg-with-implicits/overloaded-implicit.scala new file mode 100644 index 000000000..68b1ceaa3 --- /dev/null +++ b/tests/untried/neg-with-implicits/overloaded-implicit.scala @@ -0,0 +1,17 @@ +object Test { + implicit def imp1[T](x: List[T]): Map[T, T] = Map() + implicit def imp1[T](x: Set[T]): Map[T, T] = Map() + + def f[T <% Map[Int, Int]](x: T): Double = 1.0d + + // not parameterized, no warning + implicit def imp2(x: List[Int]): String = "a" + implicit def imp2(x: Set[Int]): String = "b" + + def g[T <% String](x: T): Double = 2.0d + + def main(args: Array[String]): Unit = { + // println(f(List(1))) + println(g(List(1))) + } +} diff --git a/tests/untried/neg-with-implicits/patmat-classtag-compound.scala b/tests/untried/neg-with-implicits/patmat-classtag-compound.scala new file mode 100644 index 000000000..e2d0df0a0 --- /dev/null +++ b/tests/untried/neg-with-implicits/patmat-classtag-compound.scala @@ -0,0 +1,17 @@ +object Test extends App{ + trait Bar + trait Foo + // Failed to give an unchecked warning pre: https://github.com/scala/scala/pull/2848 + // + // Features interacting: + // - implicit class tags to enable type patterns on abstract types + // - type tests on compound types. + // + // We could try make these work together, but an unchecked warning is okay for now. + def x[A: reflect.ClassTag](a: Any): Boolean = a match{ + case b: A with Bar => true + case _ => false + } + println(x[Foo](new Bar{})) + println(x[String]("")) +} diff --git a/tests/untried/neg-with-implicits/sammy_restrictions.scala b/tests/untried/neg-with-implicits/sammy_restrictions.scala new file mode 100644 index 000000000..5f1a04cd2 --- /dev/null +++ b/tests/untried/neg-with-implicits/sammy_restrictions.scala @@ -0,0 +1,45 @@ +class NoAbstract + +class TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int } + +class Base // check that the super class constructor isn't considered. +class NoEmptyConstructor(a: Int) extends Base { def this(a: String) = this(0); def ap(a: Int): Int } + +class OneEmptyConstructor() { def this(a: Int) = this(); def ap(a: Int): Int } + +class OneEmptySecondaryConstructor(a: Int) { def this() = this(0); def ap(a: Int): Int } + +class MultipleConstructorLists()() { def ap(a: Int): Int } + +class MultipleMethodLists()() { def ap(a: Int)(): Int } + +class ImplicitConstructorParam()(implicit a: String) { def ap(a: Int): Int } + +class ImplicitMethodParam() { def ap(a: Int)(implicit b: String): Int } + +class PolyClass[T] { def ap(a: T): T } + +class PolyMethod { def ap[T](a: T): T } + +class OneAbstract { def ap(a: Any): Any } +class DerivedOneAbstract extends OneAbstract + +object Test { + implicit val s: String = "" + type NonClassType = DerivedOneAbstract with OneAbstract + + (() => 0) : NoAbstract + ((x: Int) => 0): TwoAbstract + ((x: Int) => 0): DerivedOneAbstract // okay + ((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here. + ((x: Int) => 0): NoEmptyConstructor + ((x: Int) => 0): OneEmptyConstructor // okay + ((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call. + ((x: Int) => 0): MultipleConstructorLists + ((x: Int) => 0): MultipleMethodLists + ((x: Int) => 0): ImplicitConstructorParam + ((x: Int) => 0): ImplicitMethodParam + + ((x: Int) => 0): PolyClass[Int] // okay + ((x: Int) => 0): PolyMethod +} diff --git a/tests/untried/neg-with-implicits/sensitive2.scala b/tests/untried/neg-with-implicits/sensitive2.scala new file mode 100644 index 000000000..e0cf515bd --- /dev/null +++ b/tests/untried/neg-with-implicits/sensitive2.scala @@ -0,0 +1,8 @@ +object Test { + class Foo[A](z: A) + implicit def foo1[A](a: A): Foo[A] = new Foo(a) + implicit def foo2(a: Any): Foo[String] = new Foo("123") + + val a: Foo[_] = "abc" + +} diff --git a/tests/untried/neg-with-implicits/stringinterpolation_macro-neg.scala b/tests/untried/neg-with-implicits/stringinterpolation_macro-neg.scala new file mode 100644 index 000000000..3869d42d6 --- /dev/null +++ b/tests/untried/neg-with-implicits/stringinterpolation_macro-neg.scala @@ -0,0 +1,76 @@ +object Test extends App { + val s = "Scala" + val d = 8 + val b = false + val f = 3.14159 + val c = 'c' + val t = new java.util.Date + val x = new java.util.Formattable { + def formatTo(ff: java.util.Formatter, g: Int, w: Int, p: Int): Unit = ff format "xxx" + } + + // 1) number of arguments + new StringContext().f() + new StringContext("", " is ", "%2d years old").f(s) + new StringContext("", " is ", "%2d years old").f(s, d, d) + new StringContext("", "").f() + + // 2) Interpolation mismatches + f"$s%b" + f"$s%c" + f"$f%c" + f"$s%x" + f"$b%d" + f"$s%d" + f"$f%o" + f"$s%e" + f"$b%f" + + { + implicit val strToInt1 = (s: String) => 1 + implicit val strToInt2 = (s: String) => 2 + f"$s%d" + } + + f"$s%i" + + // 3) flag mismatches + f"$s%+ 0,(s" + f"$c%#+ 0,(c" + f"$d%#d" + f"$d%,x" + f"$d%+ (x" + f"$f%,(a" + f"$t%#+ 0,(tT" + + // 4) bad precisions + f"$c%.2c" + f"$d%.2d" + f"%.2%" + f"%.2n" + f"$f%.2a" + f"$t%.2tT" + + // 5) bad indexes + f"% y} + def y: Int = 0 + implicitly[Int] + } +} diff --git a/tests/untried/neg-with-implicits/t2421b.scala b/tests/untried/neg-with-implicits/t2421b.scala new file mode 100644 index 000000000..4e23a74e8 --- /dev/null +++ b/tests/untried/neg-with-implicits/t2421b.scala @@ -0,0 +1,17 @@ +object Test { + class A + class B + class C + class F[X] + + def f(implicit aa: F[A]) = println(aa) + + // implicit def a : F[A] = new F[A]() + implicit def b[X <: B] = new F[X]() + + f +} + +/* bug: +error: type arguments [Test2.A] do not conform to method b's type parameter bounds [X <: Test2.B] +*/ diff --git a/tests/untried/neg-with-implicits/t3006.scala b/tests/untried/neg-with-implicits/t3006.scala new file mode 100755 index 000000000..a84b69c84 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3006.scala @@ -0,0 +1,10 @@ +object Test extends App { + case class A(x: Int); + + class Foo(a: A) { println("Foo created!"); def +(x: Int) = new A(this.a.x + x); } + + implicit def aToFoo(x: A) = new Foo(x); + + println(A(3) + "H") + +} diff --git a/tests/untried/neg-with-implicits/t3224.scala b/tests/untried/neg-with-implicits/t3224.scala new file mode 100755 index 000000000..b7af8a67b --- /dev/null +++ b/tests/untried/neg-with-implicits/t3224.scala @@ -0,0 +1,50 @@ +object Texts{ + def textL[T](list: List[T]) = { + list match{ + case List() => "Empty" + case List(_) => "One" + case List(_*) => "Many" + } + } + + def textA[T](array: Array[T]) = { + array match{ + case Array() => "Empty" + case Array(_) => "One" + case Array(_*) => "Many" + } + } +} + +object Test extends App { + { + implicit def array2list[T](array: Array[T]) = { + println(array.toList.size) + array.toList + } + + println(Texts textL List()) + println(Texts textL List(1)) + println(Texts textL List(1, 1)); + + println(Texts textL Array()) + println(Texts textL Array(1)) + println(Texts textL Array(1, 1)) + + println(Texts textA List()) + println(Texts textA List(1)) + println(Texts textA List(1, 1)); + + println(Texts textA Array()) + println(Texts textA Array(1)) + println(Texts textA Array(1, 1)) + } + + { + implicit def array2list[T](array: Array[T]) = array.toList + def size[T](list: List[T]) = list.size + + assert(size(array2list(Array())) == 0) + assert(size(Array()) == 0) + } +} diff --git a/tests/untried/neg-with-implicits/t3346b.scala b/tests/untried/neg-with-implicits/t3346b.scala new file mode 100644 index 000000000..f28ee8ba3 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3346b.scala @@ -0,0 +1,15 @@ +import scala.language.implicitConversions + +trait T[X] +trait U[X] +trait TC[M[_]] + +object Test extends App { + def foo[M[_]: TC, A](ma: M[A]) = () + implicit val TCofT: TC[T] = new TC[T] {} + implicit def any2T[A](a: A): T[A] = new T[A] {} + implicit def any2U[A](a: A): U[A] = new U[A] {} + + val x = foo[T, Int](1) + val y = foo(1) +} diff --git a/tests/untried/neg-with-implicits/t3346c.scala b/tests/untried/neg-with-implicits/t3346c.scala new file mode 100644 index 000000000..a5ac166b2 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3346c.scala @@ -0,0 +1,61 @@ +object Test extends App { + // + // An attempt to workaround SI-2712, foiled by SI-3346 + // + trait TC[M[_]] + + type EitherInt[A] = Either[Int, A] + + implicit object EitherTC extends TC[EitherInt] + + def foo[M[_]: TC, A](ma: M[A]) = () + + val eii: Either[Int, String] = Right("") + + foo[EitherInt, String](eii) + + // This one needs SI-2712 Higher Order Unification + //foo(eii) // not inferred + + // A workaround is to provide a set of implicit conversions that take values + // based on type constructors of various shapes, and search for the + // type class instances. + // + // This is the approach taken by scalaz7. + + trait TCValue[M[_], A] { + implicit def self: M[A] + def M: TC[M] + + // instead of `foo(eii)`, we'll try `eii.foo` + def foo[M[_], A] = () + } + + + implicit def ToTCValue[M[_], A](ma: M[A])(implicit M0: TC[M]) = new TCValue[M, A] { + implicit val M = M0 + val self = ma + } + implicit def ToTCValueBin1[M[_, _], A, B](ma: M[A, B])(implicit M0: TC[({type λ[α]=M[A, α]})#λ]): TCValue[({type λ[α] = M[A, α]})#λ, B] = new TCValue[({type λ[α]=M[A, α]})#λ, B] { + implicit val M = M0 + val self = ma + } + implicit def ToTCValueBin2[M[_, _], A, B](ma: M[A, B])(implicit M0: TC[({type λ[α]=M[α, B]})#λ]): TCValue[({type λ[α]=M[α, B]})#λ, A] = new TCValue[({type λ[α]=M[α, B]})#λ, A] { + implicit val M = M0 + val self = ma + } + + + ToTCValueBin1(eii).foo + + // as expected, could not find implicit parameter + // ToTCValueBin2(eii).bar + + // error: implicit conversions are not applicable because they are ambiguous, both method ToTCValueBin1 ... and method ToTCValueBin2 + // annoying!! + // https://issues.scala-lang.org/browse/SI-3346 + // + // Works if we remove ToTCValueBin2 + // + eii.bar +} diff --git a/tests/untried/neg-with-implicits/t3346i.scala b/tests/untried/neg-with-implicits/t3346i.scala new file mode 100644 index 000000000..9ad254453 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3346i.scala @@ -0,0 +1,30 @@ +import scala.language.implicitConversions + +// the classes involved +case class Z[U](a: U) +case class Intermediate[T, U](t: T, u: U) +class Implicit1[T](b: Implicit2[T]) +class Implicit2[T](c: Implicit3[T]) +class Implicit3[T](/* and so on */) + +object Test extends App { + // the base conversion + implicit def convertToZ[T](a: A[T])(implicit b: Implicit1[T]): Z[A[T]] = Z(a) + + // and the implicit chaining, don't you just love it? :D + // implicit1, with one alternative + implicit def implicit1[T <: Intermediate[_, _]](implicit b: Implicit2[T]) = new Implicit1[T](b) + // implicit2, with two alternatives + implicit def implicit2alt1[T <: Intermediate[_ <: String, _]](implicit c: Implicit3[T]) = new Implicit2[T](c) + implicit def implicit2alt2[T <: Intermediate[_ <: Double, _]](implicit c: Implicit3[T]) = new Implicit2[T](c) + // implicit3, with two alternatives + implicit def implicit3alt1[T <: Intermediate[_, _ <: Int]] = new Implicit3[T]() + implicit def implicit3alt2[T <: Intermediate[_ <: Double, _ <: AnyRef],X] = new Implicit3[T]() + + // and our targets + /** conversion here, with constraints */ + class A[T]() + + (new A).a + (new A[Nothing]).a +} diff --git a/tests/untried/neg-with-implicits/t3453.scala b/tests/untried/neg-with-implicits/t3453.scala new file mode 100644 index 000000000..af7781894 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3453.scala @@ -0,0 +1,66 @@ +// test shadowing of implicits by synonymous non-implicit symbols +// whether they be inherited, imported (explicitly or using a wildcard) or defined directly +class A +class B + +trait S { + implicit def aToB(a: A): B = new B +} + +class T1 extends S { + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} + +object O { + implicit def aToB(a: A): B = new B +} + +class T2a { + import O._ + + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} + +class T2b { + import O.aToB + + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} + +class T3 { + implicit def aToB(a: A): B = new B + + def x: B = { + val aToB = 3 + // ok: doesn't compile, because aToB method requires 'T.this.' prefix + //aToB(new A) + + // bug: compiles, using T.this.aToB, + // despite it not being accessible without a prefix + new A + } +} diff --git a/tests/untried/neg-with-implicits/t3653.scala b/tests/untried/neg-with-implicits/t3653.scala new file mode 100644 index 000000000..0bedc4fdc --- /dev/null +++ b/tests/untried/neg-with-implicits/t3653.scala @@ -0,0 +1,4 @@ +class B { + def x(i: Int) = 3 + def x(implicit x: Int) = 5 +} diff --git a/tests/untried/neg-with-implicits/t3692-new.scala b/tests/untried/neg-with-implicits/t3692-new.scala new file mode 100644 index 000000000..6ecf4acb8 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3692-new.scala @@ -0,0 +1,20 @@ +import scala.reflect.{ClassTag, classTag} +import java.lang.Integer + +object Tester { + def main(args: Array[String]) = { + val map = Map("John" -> 1, "Josh" -> 2) + new Tester().toJavaMap(map) + } +} + +class Tester { + private final def toJavaMap[T, V](map: Map[T, V])(implicit m1: ClassTag[T], m2: ClassTag[V]): java.util.Map[_, _] = { + map match { + case m0: Map[Int, Int] => new java.util.HashMap[Integer, Integer] + case m1: Map[Int, V] => new java.util.HashMap[Integer, V] + case m2: Map[T, Int] => new java.util.HashMap[T, Integer] + case _ => new java.util.HashMap[T, V] + } + } +} diff --git a/tests/untried/neg-with-implicits/t3776.scala b/tests/untried/neg-with-implicits/t3776.scala new file mode 100644 index 000000000..e24b2fea6 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3776.scala @@ -0,0 +1,10 @@ +object MyParser { + implicit def literal(s: String): Parser[String] = ??? + trait Parser[+T] + def parse[T](p: Parser[T], in: java.lang.CharSequence): Option[T] = ??? +} +object Test { + class ParsedAs(a: String) (implicit pattern: MyParser.Parser[_]) { + def parsedAs[T](v: T) = MyParser.parse(pattern, a).get someOperation v + } +} diff --git a/tests/untried/neg-with-implicits/t3854.scala b/tests/untried/neg-with-implicits/t3854.scala new file mode 100644 index 000000000..e8db76c0a --- /dev/null +++ b/tests/untried/neg-with-implicits/t3854.scala @@ -0,0 +1,15 @@ +class Bar[F[_]] extends Foo[F] { + def foo[G[_[_], _]](implicit M: M[G]): X[({type λ[α] = G[F, α] })#λ] = null +} +// vim: set ts=4 sw=4 et: + +trait M[F[_[_], _]] +trait N[F[_], G[_]] + +trait X[F[_]] { + def apply[A]: F[A] +} + +trait Foo[F[_]] { + def foo[G[_]](implicit n: N[G, F]): X[F] +} diff --git a/tests/untried/neg-with-implicits/t3977.scala b/tests/untried/neg-with-implicits/t3977.scala new file mode 100644 index 000000000..11a8cdba4 --- /dev/null +++ b/tests/untried/neg-with-implicits/t3977.scala @@ -0,0 +1,13 @@ +trait Bool { + type If[T] +} + +trait False extends Bool { + type If[F] = F +} + +class Field[E, N <: Bool](implicit val w: N#If[E]) { + type NoNull = Field[E, False] + + new NoNull +} diff --git a/tests/untried/neg-with-implicits/t3995.scala b/tests/untried/neg-with-implicits/t3995.scala new file mode 100644 index 000000000..be169639d --- /dev/null +++ b/tests/untried/neg-with-implicits/t3995.scala @@ -0,0 +1,32 @@ +class Lift { + def apply(f: F0): Unit = {} + + class F0 + object F0 { + implicit def f2f0(fn: String): F0 = ??? + } +} + +object Test { + val l = new Lift + val f = "" + + "": l.F0 // okay + + l.apply("") // okay + + { + val l = new Lift + l.apply("") // okay + } + + // fails trying to mkAttributedQualifier for pre = Skolem(_1 <: Lift with Singletom).F0 + // should this even have shown up in `companionImplicitMap`? It says that: + // + // "@return For those parts that refer to classes with companion objects that + // can be accessed with unambiguous stable prefixes, the implicits infos + // which are members of these companion objects." + // + // The skolem is stable, but it doen't seem much good to us + (new Lift).apply("") +} diff --git a/tests/untried/neg-with-implicits/t4079/t4079_1.scala b/tests/untried/neg-with-implicits/t4079/t4079_1.scala new file mode 100644 index 000000000..cbae86478 --- /dev/null +++ b/tests/untried/neg-with-implicits/t4079/t4079_1.scala @@ -0,0 +1,33 @@ +trait Functor[F[_]] { + def map[A,B](fa: F[A], f: A => B): F[B] +} + +trait ComposeT[F[_],G[_]] { + type Apply[A] = F[G[A]] +} + +case class Compose[F[_],G[_]]() { + def Functor(implicit f: Functor[F], g: Functor[G]): Functor[ComposeT[F,G]#Apply] = + new Functor[ComposeT[F,G]#Apply] { + def map[A,B](c: ComposeT[F,G]#Apply[A], h: A => B) = + f.map(c, (x:G[A]) => g.map(x,h)) + } +} + +object Cat { + def compose[F[_],G[_]] = Compose[F,G]() +} + +object Functors { + implicit val List = new Functor[List] { + def map[A,B](fa: List[A], f: A => B): List[B] = fa map f + } + implicit val Option = new Functor[Option] { + def map[A,B](fa: Option[A], f: A => B): Option[B] = fa map f + } +} + +object Main { + import Functors._ + val cf = Cat.compose[List,Option].Functor +} diff --git a/tests/untried/neg-with-implicits/t4079/t4079_2.scala b/tests/untried/neg-with-implicits/t4079/t4079_2.scala new file mode 100644 index 000000000..9069f0ab4 --- /dev/null +++ b/tests/untried/neg-with-implicits/t4079/t4079_2.scala @@ -0,0 +1,3 @@ +object Test { + Cat.compose[List,Option].Functor +} diff --git a/tests/untried/neg-with-implicits/t4270.scala b/tests/untried/neg-with-implicits/t4270.scala new file mode 100644 index 000000000..2c7c71d8c --- /dev/null +++ b/tests/untried/neg-with-implicits/t4270.scala @@ -0,0 +1,6 @@ +object Test1 { + object A { implicit val x: Int = 1 } + import A.x + def x: Int = 0 + implicitly[Int] +} diff --git a/tests/untried/neg-with-implicits/t4271.scala b/tests/untried/neg-with-implicits/t4271.scala new file mode 100644 index 000000000..46ae3ad9e --- /dev/null +++ b/tests/untried/neg-with-implicits/t4271.scala @@ -0,0 +1,12 @@ +object foo { + object Donotuseme + implicit def Ensuring[A](x: A) = Donotuseme + implicit def doubleWrapper(x: Int) = Donotuseme + implicit def floatWrapper(x: Int) = Donotuseme + implicit def intWrapper(x: Int) = Donotuseme + implicit def longWrapper(x: Int) = Donotuseme + implicit def ArrowAssoc[A](x: A) = Donotuseme + 3 to 5 + 5 ensuring true + 3 -> 5 +} diff --git a/tests/untried/neg-with-implicits/t4457_1.scala b/tests/untried/neg-with-implicits/t4457_1.scala new file mode 100644 index 000000000..11dae1097 --- /dev/null +++ b/tests/untried/neg-with-implicits/t4457_1.scala @@ -0,0 +1,33 @@ +object ImplicitConvAmbiguity2 { + + class N[T] + class NE[T] extends N[T] + class NN[T] extends N[T] + class NQ[T] extends N[T] + class NZ[T] extends N[T] + class AA[A] + class BB[A] + + implicit def conv1(i: Float) = new NE[Float] + implicit def conv3(op: AA[java.util.TooManyListenersException]) = new N[java.util.TooManyListenersException] + implicit def conv4(op: AA[Float]) = new N[Float] + implicit def conv7(i: Float) = new NZ[Float] + implicit def conv5(e: BB[java.util.GregorianCalendar]) = new N[java.util.GregorianCalendar] + + // These two will be in conflict in typeMe1 + def aFunc[A](a: NE[A]) = new AA[A] + def aFunc[A](a: NZ[A]) = new AA[Float] + + def aFunc[A](a: NN[A]) = new BB[A] + def aFunc[A](a: NQ[A]) = new BB[A] + + def bFunc[T](e1: N[T]) = {} + + def typeMe1: Unit = { + val x = aFunc(4F) + bFunc(x) + } + def typeMe2: Unit = { + bFunc(aFunc(4F)) + } +} diff --git a/tests/untried/neg-with-implicits/t4457_2.scala b/tests/untried/neg-with-implicits/t4457_2.scala new file mode 100644 index 000000000..f2664cc14 --- /dev/null +++ b/tests/untried/neg-with-implicits/t4457_2.scala @@ -0,0 +1,33 @@ +object ImplicitConvAmbiguity2 { + + class N[T] + class NE[T] extends N[T] + class NN[T] extends N[T] + class NQ[T] extends N[T] + class NZ[T] extends N[T] + class AA[A] + class BB[A] + + implicit def conv1(i: Float) = new NE[Float] + implicit def conv3(op: AA[java.util.TooManyListenersException]) = new N[java.util.TooManyListenersException] + implicit def conv4(op: AA[Float]) = new N[Float] + implicit def conv7(i: Float) = new NZ[Float] + implicit def conv5(e: BB[java.util.GregorianCalendar]) = new N[java.util.GregorianCalendar] + + def aFunc[A](a: NE[A]) = new AA[A] + def aFunc[A](a: NZ[A]) = new AA[A] + + def aFunc[A](a: NN[A]) = new BB[A] + + def aFunc[A](a: NQ[A]) = new BB[A] + + def bFunc[T](e1: N[T]) = {} + + def typeMe2: Unit = { + val x = aFunc(4F) + bFunc(x) + } + def typeMe1: Unit = { + bFunc(aFunc(4F)) + } +} diff --git a/tests/untried/neg-with-implicits/t4568.scala b/tests/untried/neg-with-implicits/t4568.scala new file mode 100644 index 000000000..6fda28736 --- /dev/null +++ b/tests/untried/neg-with-implicits/t4568.scala @@ -0,0 +1,13 @@ +object SubList { + implicit def sublistable[A](x: List[A]) = new SubListable(x) + + class SubListable[A](x: List[A]) { + def isSubListOf(y: List[A]) = { + x match { + case Nil => true + case h :: t => y.contains(h) && (t.isSubListOf(y.drop(y.indexOf(h) + 1))) + } + } + } + +} diff --git a/tests/untried/neg-with-implicits/t4882.scala b/tests/untried/neg-with-implicits/t4882.scala new file mode 100644 index 000000000..4e58ef787 --- /dev/null +++ b/tests/untried/neg-with-implicits/t4882.scala @@ -0,0 +1,3 @@ +class Foo(value: Int) { + implicit def this(a: String) = this(a.toInt) +} diff --git a/tests/untried/neg-with-implicits/t5318.scala b/tests/untried/neg-with-implicits/t5318.scala new file mode 100644 index 000000000..5be82a02a --- /dev/null +++ b/tests/untried/neg-with-implicits/t5318.scala @@ -0,0 +1,8 @@ +class CompilerHang { + trait TC[M[_]] + trait S[A] + + implicit def tc[M[_]](implicit M0: TC[M]): TC[S] = null + def breakage[F[_] : TC] = 0 + breakage // type checker doesn't terminate, should report inference failure +} diff --git a/tests/untried/neg-with-implicits/t5318b.scala b/tests/untried/neg-with-implicits/t5318b.scala new file mode 100644 index 000000000..a2d55b1e4 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5318b.scala @@ -0,0 +1,8 @@ +class DivergingImplicitReported { + trait TC[M] + trait S + + implicit def tc[M](implicit M0: TC[M]): TC[S] = null + def breakage[F: TC] = 0 + breakage // correct: diverging implicit expansion +} diff --git a/tests/untried/neg-with-implicits/t5318c.scala b/tests/untried/neg-with-implicits/t5318c.scala new file mode 100644 index 000000000..477a9874a --- /dev/null +++ b/tests/untried/neg-with-implicits/t5318c.scala @@ -0,0 +1,14 @@ +class CompilerHang { + trait TC[M[_]] + trait S[A] + + class C[M[_]] { + type TCM = TC[M] + } + + // A nefarious implicit, to motivate the removal of `&& sym.owner.isTerm` from + // `isFreeTypeParamNoSkolem`. + implicit def tc[x[_], CC[x[_]] <: C[x]](implicit M0: CC[x]#TCM): CC[x]#TCM = null + def breakage[F[_] : TC] = 0 + breakage // type checker doesn't terminate, should report inference failure +} diff --git a/tests/untried/neg-with-implicits/t5340.scala b/tests/untried/neg-with-implicits/t5340.scala new file mode 100644 index 000000000..b283f1333 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5340.scala @@ -0,0 +1,29 @@ +class Poly { + class E + object E { + implicit def conv(value: Any): E = sys.error("") + } +} + +object MyApp { + val r: Poly = sys.error("") + val s: Poly = sys.error("") + val b: r.E = sys.error("") + + // okay + s.E.conv(b): s.E + + // compilation fails with error below + println(b: s.E) + + // amb prefix: MyApp.s.type#class E MyApp.r.type#class E + // amb prefix: MyApp.s.type#class E MyApp.r.type#class E + // ../test/pending/run/t5310.scala:17: error: type mismatch; + // found : MyApp.r.E + // required: MyApp.s.E + // println(b: s.E) + // ^ + + // The type error is as expected, but the `amb prefix` should be logged, + // rather than printed to standard out. +} diff --git a/tests/untried/neg-with-implicits/t5354.scala b/tests/untried/neg-with-implicits/t5354.scala new file mode 100644 index 000000000..99b565015 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5354.scala @@ -0,0 +1,15 @@ +package object foo { + implicit def x123: Bippy = new Bippy("x") +} +package foo { + class Bippy(override val toString: String){ } + class Dingus { + def f1 = { + implicit def z: Bippy = new Bippy("z") + implicitly[Bippy] + } + } + object Test extends App { + println(new Dingus().f1) + } +} diff --git a/tests/untried/neg-with-implicits/t5376.scala b/tests/untried/neg-with-implicits/t5376.scala new file mode 100644 index 000000000..9dcaccbf1 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5376.scala @@ -0,0 +1,24 @@ +object Test { + object O1 { implicit def f(s: String): Int = 1 } + object O2 { implicit def f(s: String): Int = 2 } + object O3 { def f(s: String): Int = 3 } + + // Import two implicits with the same name in the same scope. + def m1 = { + import O1._ + import O2._ + + // Implicit usage compiles. + "a": Int + } + + // Import one implict and one non-implicit method with the + // same name in the same scope. + def m2 = { + import O1._ + import O3._ + + // Implicit usage compiles. + "a": Int + } +} diff --git a/tests/untried/neg-with-implicits/t550.scala b/tests/untried/neg-with-implicits/t550.scala new file mode 100644 index 000000000..5212a2658 --- /dev/null +++ b/tests/untried/neg-with-implicits/t550.scala @@ -0,0 +1,9 @@ +abstract class Monoid[a] { + def unit: a +} + +object test { + def sum[a](xs: List)(implicit m: Monoid[a]): a = + if (xs.isEmpty) m.unit else xs.head + sum(List(1,2,3)) +} diff --git a/tests/untried/neg-with-implicits/t5553_2.scala b/tests/untried/neg-with-implicits/t5553_2.scala new file mode 100644 index 000000000..16958aec8 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5553_2.scala @@ -0,0 +1,59 @@ +class Base[T] + +object Foo1 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int, z: String="abc"): String = z +} + +object Foo2 { + def apply[T](a: Int): Base[T] = new Base[T] + def apply[T]: String = "abc" +} + +object Foo3 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](implicit z: String): String = z +} + +object Foo4 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int)(implicit z: String): Base[T] = new Base[T] +} + +object Test1 { + def test1[T] = Foo1[T](1) + def test2[T]: String = Foo1[T](1) + def test3[T]: Base[T] = Foo1[T](1) + def test4[T]: Int = Foo1[T](1) + +} + +object Test2 { + def test5[T] = Foo2[T] + def test6[T]: String = Foo2[T] + def test7[T]: Base[T] = Foo2[T] + def test8[T]: Int = Foo2[T] +} + +object Test3 { + implicit val v: String = "abc" + def test9[T]: Int = Foo3[T] + def test10[T]: Base[T] = Foo3[T] + def test11[T]: String = Foo3[T] + def test12[T] = Foo3[T] +} + +object Test4 { + def test13[T]: Int = Foo3[T] + def test14[T]: Base[T] = Foo3[T] + def test15[T]: String = Foo3[T] + def test16[T] = Foo3[T] +} + +object Test5 { + def test17[T] = Foo4[T](1) + def test18[T]: Base[T] = Foo4[T](1) + //def test19[T]: String = Foo4[T](1) // #5554 +} + + diff --git a/tests/untried/neg-with-implicits/t5554.scala b/tests/untried/neg-with-implicits/t5554.scala new file mode 100644 index 000000000..d279abea7 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5554.scala @@ -0,0 +1,39 @@ +class Base[T] + +object Foo1 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int)(implicit z: String): String = z +} + +object Foo2 { + def apply[T](x: Int): Base[T] = new Base[T] + def apply[T](x: Int)(implicit z: String): Base[T] = new Base[T] +} + +object Test1 { + def test1[T]: Int = Foo1[T](1) + def test2[T]: Base[T] = Foo1[T](1) + def test3[T]: String = Foo1[T](1) + def test4[T] = Foo1[T](1) +} + +object Test2 { + implicit val v: String = "foo" + def test5[T]: Int = Foo1[T](1) + def test6[T]: Base[T] = Foo1[T](1) + def test7[T]: String = Foo1[T](1) + def test8[T] = Foo1[T](1) +} + +object Test3 { + def test9[T]: String = Foo2[T](1) + def test10[T]: Base[T] = Foo2[T](1) + def test11[T] = Foo2[T](1) +} + +object Test4 { + implicit val v: String = "foo" + def test12[T]: String = Foo2[T](1) + def test13[T]: Base[T] = Foo2[T](1) + def test14[T] = Foo2[T](1) +} diff --git a/tests/untried/neg-with-implicits/t5578.scala b/tests/untried/neg-with-implicits/t5578.scala new file mode 100644 index 000000000..ce72f32d5 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5578.scala @@ -0,0 +1,39 @@ +trait Base { + type Rep[T] +} + +trait Expressions { + // constants/symbols (atomic) + abstract class Exp[T] + // ... + case class Sym[T](n: Int) extends Exp[T] + + // operations (composite, defined in subtraits) + abstract class Def[T] + + // additional members for managing encountered definitions + def findOrCreateDefinition[T](rhs: Def[T]): Sym[T] + implicit def toExp[T:Manifest](d: Def[T]): Exp[T] = findOrCreateDefinition(d) +} + +trait BaseExp extends Base with Expressions { + type Rep[T] = Exp[T] + + def findOrCreateDefinition[T](rhs: Def[T]): Sym[T] = null // stub +} + +trait NumericOps extends Base { + def plus[T](x: Rep[T], y: Rep[T]): Rep[T] +} + +trait NumericOpsExp extends BaseExp { + case class Plus[T:Numeric](x: Rep[T], y: Rep[T]) + extends Def[T] + + def plus[T: Numeric](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x,y) + + // Possible solutions: +// def plus[T: Numeric: Manifest](x: Rep[T], y: Rep[T]): Rep[T] = Plus[T](x, y) +// def plus[T](x: Rep[T], y: Rep[T])(implicit num: Numeric[T], man: Manifest[T]): Rep[T] = Plus(x,y) + +} diff --git a/tests/untried/neg-with-implicits/t5728.scala b/tests/untried/neg-with-implicits/t5728.scala new file mode 100644 index 000000000..99337d06d --- /dev/null +++ b/tests/untried/neg-with-implicits/t5728.scala @@ -0,0 +1,7 @@ +object Test { + + implicit class Foo + + implicit def Foo = new Foo + +} diff --git a/tests/untried/neg-with-implicits/t5801.scala b/tests/untried/neg-with-implicits/t5801.scala new file mode 100644 index 000000000..d452222ac --- /dev/null +++ b/tests/untried/neg-with-implicits/t5801.scala @@ -0,0 +1,16 @@ +import scala.sth + +object Test extends App { + def foo(a: Int)(implicit b: sth.Sth): Unit = {} + foo(1) + + def bar(x: Int)(implicit y: Int): sth.Sth = null + bar(1) + + def meh(x: Int)(implicit a: sth.Sth, b: Int): Unit = {} + meh(1) + + def meh2(x: Int)(implicit b: Int, a: sth.Sth): Unit = {} + meh2(1) +} + diff --git a/tests/untried/neg-with-implicits/t5803.scala b/tests/untried/neg-with-implicits/t5803.scala new file mode 100644 index 000000000..f818272f8 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5803.scala @@ -0,0 +1,4 @@ +object Test { + class Foo()(implicit ev: Nothing) + new Foo(): String +} diff --git a/tests/untried/neg-with-implicits/t5839.scala b/tests/untried/neg-with-implicits/t5839.scala new file mode 100644 index 000000000..d3a5d4b25 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5839.scala @@ -0,0 +1,7 @@ +object Test { + def goo[T](x: Int => T): T = x(1) + implicit def f(x: Int): String = "" + def foo(x: Int): Int = x + 1 + val x: String = goo(foo _) + def foo(x: String => String) = 1 +} diff --git a/tests/untried/neg-with-implicits/t5892.scala b/tests/untried/neg-with-implicits/t5892.scala new file mode 100644 index 000000000..5e3b2f313 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5892.scala @@ -0,0 +1,25 @@ +import language.implicitConversions + +class annot(a: String) extends annotation.StaticAnnotation + +class C[@annot(false) X] { + implicit def b2s(b: Boolean): String = "" +} + +class D[@annot(b2s(false)) X] { + implicit def b2s(b: Boolean): String = "" +} + +@annot(false) class E { + implicit def b2s(b: Boolean): String = "" +} + +@annot(b2s(false)) class F { + implicit def b2s(b: Boolean): String = "" +} + +object T { + implicit def b2s(b: Boolean): String = "" + @annot(false) val x = 0 + @annot(b2s(false)) val y = 0 +} diff --git a/tests/untried/neg-with-implicits/t5903a/Macros_1.scala b/tests/untried/neg-with-implicits/t5903a/Macros_1.scala new file mode 100644 index 000000000..5d084ceed --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903a/Macros_1.scala @@ -0,0 +1,28 @@ +import scala.reflect.macros.whitebox.Context +import language.experimental.macros + +trait Tree +case object SomeTree extends Tree + +object NewQuasiquotes { + implicit class QuasiquoteInterpolation(c: StringContext) { + object nq { + def unapply(t: Tree): Any = macro QuasiquoteMacros.unapplyImpl + } + } +} + +object QuasiquoteMacros { + def unapplyImpl(c: Context)(t: c.Tree) = { + import c.universe._ + q""" + new { + def isEmpty = false + def get = this + def _1 = SomeTree + def _2 = SomeTree + def unapply(t: Tree) = this + }.unapply($t) + """ + } +} diff --git a/tests/untried/neg-with-implicits/t5903a/Test_2.scala b/tests/untried/neg-with-implicits/t5903a/Test_2.scala new file mode 100644 index 000000000..4d78dfb5e --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903a/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import NewQuasiquotes._ + SomeTree match { + case nq"$x + $y + $z" => println((x, y)) + } +} diff --git a/tests/untried/neg-with-implicits/t5903b/Macros_1.scala b/tests/untried/neg-with-implicits/t5903b/Macros_1.scala new file mode 100644 index 000000000..6ce49c022 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903b/Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply[T](x: T): Any = macro Macros.unapplyImpl[T] + } + } +} + +object Macros { + def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + import c.universe._ + q""" + new { + def isEmpty = false + def get = "2" + def unapply(x: String) = this + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg-with-implicits/t5903b/Test_2.scala b/tests/untried/neg-with-implicits/t5903b/Test_2.scala new file mode 100644 index 000000000..0f6f80d32 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903b/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Interpolation._ + 2 match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg-with-implicits/t5903c/Macros_1.scala b/tests/untried/neg-with-implicits/t5903c/Macros_1.scala new file mode 100644 index 000000000..4792f0045 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903c/Macros_1.scala @@ -0,0 +1,26 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply[T](x: T): Any = macro Macros.unapplyImpl[T] + } + } +} + +object Macros { + def unapplyImpl[T: c.WeakTypeTag](c: Context)(x: c.Tree) = { + import c.universe._ + if (!(c.weakTypeOf[Int] =:= c.weakTypeOf[T])) c.abort(c.enclosingPosition, s"${c.weakTypeOf[T]} is not supported") + else { + q""" + new { + def isEmpty = false + def get = 2 + def unapply(x: Int) = this + }.unapply($x) + """ + } + } +} diff --git a/tests/untried/neg-with-implicits/t5903c/Test_2.scala b/tests/untried/neg-with-implicits/t5903c/Test_2.scala new file mode 100644 index 000000000..a1fd31dd4 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903c/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Interpolation._ + "2" match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg-with-implicits/t5903d/Macros_1.scala b/tests/untried/neg-with-implicits/t5903d/Macros_1.scala new file mode 100644 index 000000000..3500c2a78 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903d/Macros_1.scala @@ -0,0 +1,23 @@ +import scala.reflect.macros.blackbox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply(x: Int): Any = macro Macros.unapplyImpl + } + } +} + +object Macros { + def unapplyImpl(c: Context)(x: c.Tree) = { + import c.universe._ + q""" + class Match(x: Int) { + def isEmpty = false + def get = x + } + new { def unapply(x: Int) = new Match(x) }.unapply($x) + """ + } +} diff --git a/tests/untried/neg-with-implicits/t5903d/Test_2.scala b/tests/untried/neg-with-implicits/t5903d/Test_2.scala new file mode 100644 index 000000000..95c717a9d --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903d/Test_2.scala @@ -0,0 +1,6 @@ +object Test extends App { + import Interpolation._ + 42 match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg-with-implicits/t5903e/Macros_1.scala b/tests/untried/neg-with-implicits/t5903e/Macros_1.scala new file mode 100644 index 000000000..a64ff7e0b --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903e/Macros_1.scala @@ -0,0 +1,25 @@ +import scala.reflect.macros.whitebox.Context +import language.experimental.macros + +object Interpolation { + implicit class TestInterpolation(c: StringContext) { + object t { + def unapply(x: Int): Any = macro Macros.unapplyImpl + } + } +} + +object Macros { + def unapplyImpl(c: Context)(x: c.Tree) = { + import c.universe._ + q""" + new { + class Match(x: Int) extends AnyVal { + def isEmpty = false + def get = x + } + def unapply(x: Int) = new Match(x) + }.unapply($x) + """ + } +} diff --git a/tests/untried/neg-with-implicits/t5903e/Test_2.scala b/tests/untried/neg-with-implicits/t5903e/Test_2.scala new file mode 100644 index 000000000..d69d47243 --- /dev/null +++ b/tests/untried/neg-with-implicits/t5903e/Test_2.scala @@ -0,0 +1,6 @@ +class C { + import Interpolation._ + 42 match { + case t"$x" => println(x) + } +} diff --git a/tests/untried/neg-with-implicits/t591.scala b/tests/untried/neg-with-implicits/t591.scala new file mode 100644 index 000000000..0f0b02395 --- /dev/null +++ b/tests/untried/neg-with-implicits/t591.scala @@ -0,0 +1,41 @@ +abstract class BaseList { + type Node <: BaseNode; + + + abstract class BaseNode { + protected def self : Node; + private[BaseList] def self00 = self; + def dirty : Unit = {} + def replaceWith(node : Node) = {} + } + + implicit def baseNode2Node(bnode : BaseNode): Node = bnode.self00; + + +} + + +trait BaseFlow extends BaseList { + type Node <: BFNode; + type Flow <: FlowBase; + type Output <: OutputBase; + type Input <: InputBase; + + abstract class FlowBase { + + } + trait OutputBase extends FlowBase { + + } + trait InputBase extends FlowBase { + + } + + trait BFNode extends BaseNode { + private var input : Input = _; + private var output : Output = _; + + def input_=(in : Input) = {} + + } +} diff --git a/tests/untried/neg-with-implicits/t6074.scala b/tests/untried/neg-with-implicits/t6074.scala new file mode 100644 index 000000000..8c14f00f1 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6074.scala @@ -0,0 +1,6 @@ +class A private () { } +class B { } +object T { + implicit def a2b(a: A): B = null + def t = new A() +} diff --git a/tests/untried/neg-with-implicits/t6083.scala b/tests/untried/neg-with-implicits/t6083.scala new file mode 100644 index 000000000..1de18e652 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6083.scala @@ -0,0 +1,7 @@ +object conv { + implicit def i2s(i: Int): String = "" +} +import conv._ + +class annot(value: String) extends annotation.ClassfileAnnotation +@annot(101) class C diff --git a/tests/untried/neg-with-implicits/t6120.scala b/tests/untried/neg-with-implicits/t6120.scala new file mode 100644 index 000000000..425f09db4 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6120.scala @@ -0,0 +1,7 @@ +class A { + implicit class BooleanOps(val b: Boolean) { + @deprecated("bobo", "2.11.0") def bippy() = 5 + } + def f = null == null bippy + def g = true.bippy +} diff --git a/tests/untried/neg-with-implicits/t6227.scala b/tests/untried/neg-with-implicits/t6227.scala new file mode 100644 index 000000000..46416839d --- /dev/null +++ b/tests/untried/neg-with-implicits/t6227.scala @@ -0,0 +1,6 @@ +object Test { + implicit case class IntOps( i: Int ) { + def twice = i * 2 + } +} + diff --git a/tests/untried/neg-with-implicits/t6263.scala b/tests/untried/neg-with-implicits/t6263.scala new file mode 100644 index 000000000..6575185b5 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6263.scala @@ -0,0 +1,6 @@ +class C(val a: Any) extends AnyVal +class A { + implicit def c2AnyRef(c: C): AnyRef = new {} + val c = new C(0) + type t = c.type +} diff --git a/tests/untried/neg-with-implicits/t631.scala b/tests/untried/neg-with-implicits/t631.scala new file mode 100644 index 000000000..631db3eb1 --- /dev/null +++ b/tests/untried/neg-with-implicits/t631.scala @@ -0,0 +1,3 @@ +implicit object Test { + Console.println("foo") +} diff --git a/tests/untried/neg-with-implicits/t6335.scala b/tests/untried/neg-with-implicits/t6335.scala new file mode 100644 index 000000000..6c898af5b --- /dev/null +++ b/tests/untried/neg-with-implicits/t6335.scala @@ -0,0 +1,7 @@ +object ImplicitClass { + def X(i: Int): Unit = {} + implicit class X(val x: Int) { def xx = x } + + def Z[A](i: A): Unit = {} + implicit class Z[A](val i: A) { def zz = i } +} diff --git a/tests/untried/neg-with-implicits/t6436.scala b/tests/untried/neg-with-implicits/t6436.scala new file mode 100644 index 000000000..2c4050253 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6436.scala @@ -0,0 +1,9 @@ +object quasiquotes { + implicit def foo1(ctx: StringContext) = new { def q = ??? } + implicit def foo2(ctx: StringContext) = new { def q = ??? } +} + +object Test extends App { + import quasiquotes._ + println(q"a") +} diff --git a/tests/untried/neg-with-implicits/t6436b.scala b/tests/untried/neg-with-implicits/t6436b.scala new file mode 100644 index 000000000..8023329e9 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6436b.scala @@ -0,0 +1,9 @@ +object quasiquotes { + implicit def foo1(ctx: StringContext) = new { def q = ??? } + implicit def foo2(ctx: StringContext) = new { def q = ??? } +} + +object Test extends App { + import quasiquotes._ + println(StringContext("a").q()) +} diff --git a/tests/untried/neg-with-implicits/t6567.scala b/tests/untried/neg-with-implicits/t6567.scala new file mode 100644 index 000000000..650e5e39a --- /dev/null +++ b/tests/untried/neg-with-implicits/t6567.scala @@ -0,0 +1,11 @@ +class A +class B + +object Test { + val a: A = null + implicit def a2b(a: A) = new B + + Option[B](a) + + val b: Option[B] = Option(a) +} diff --git a/tests/untried/neg-with-implicits/t6597.scala b/tests/untried/neg-with-implicits/t6597.scala new file mode 100644 index 000000000..dde53bcc8 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6597.scala @@ -0,0 +1,5 @@ +object Test { + trait T extends Any + implicit case class Quux(value: Int) extends AnyVal with T + object Quux +} diff --git a/tests/untried/neg-with-implicits/t6666d.scala b/tests/untried/neg-with-implicits/t6666d.scala new file mode 100644 index 000000000..49a688f91 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6666d.scala @@ -0,0 +1,18 @@ + +import scala.collection.immutable.TreeMap +import scala.math.Ordering + +class Test[K](param:TreeMap[K,Int]){ + def this() = this({ + implicit object TreeOrd extends Ordering[K](){ + def compare(a: K, b: K) = { + -1 + } + } + new TreeMap[K, Int]() + }) +} + +object Test extends App { + new Test() +} diff --git a/tests/untried/neg-with-implicits/t6667.scala b/tests/untried/neg-with-implicits/t6667.scala new file mode 100644 index 000000000..fb857ebd3 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6667.scala @@ -0,0 +1,10 @@ +class C +object C { + implicit def companion = new C +} + +object Test { + implicit val inScope1, inScope2 = new C + implicitly[C]: Unit // C.companion was used; whereas the ambiguity should abort the implicit search. + implicitly[C] // ambiguity reported, rather than falling back to C.companion +} diff --git a/tests/untried/neg-with-implicits/t6667b.scala b/tests/untried/neg-with-implicits/t6667b.scala new file mode 100644 index 000000000..db31c0a9b --- /dev/null +++ b/tests/untried/neg-with-implicits/t6667b.scala @@ -0,0 +1,25 @@ +object Test { + abstract class Box { + val value: Int + } + + implicit val a: Box = new Box { + val value= 1 + } + + def main(args: Array[String]): Unit = { + implicit val b: Box= new Box { + val value= 2 + } + + new Object { + new Test() + } + // compare with: + new Test() + } +} + +class Test()(implicit x: Test.Box) { + println(x.value) +} diff --git a/tests/untried/neg-with-implicits/t6889.scala b/tests/untried/neg-with-implicits/t6889.scala new file mode 100644 index 000000000..ef1963669 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6889.scala @@ -0,0 +1,18 @@ +package bippy { + trait Bippy[A] extends Any +} +package foo { + package object unrelated { + implicit def bippyDingo[A](x: bippy.Bippy[A]): AnyRef = Nil + } + package unrelated { + trait Unrelated + } +} + +object Test { + trait Dingo extends Any with bippy.Bippy[foo.unrelated.Unrelated] + + def f(x: Dingo): AnyRef = x // fail - no conversion to AnyRef + var x: Int = null // fail - no conversion from Null +} diff --git a/tests/untried/neg-with-implicits/t692.scala b/tests/untried/neg-with-implicits/t692.scala new file mode 100644 index 000000000..24e1d2fea --- /dev/null +++ b/tests/untried/neg-with-implicits/t692.scala @@ -0,0 +1,20 @@ +abstract class test3 { + trait Type0[+T0]; + trait Type[T0] extends Type0[T]; + trait ClassType0[+C <: AnyRef] extends Type0[C]; + abstract class RefType[C <: AnyRef] extends Type[C]; + case class ObjectType() extends RefType[AnyRef]; + abstract class ClassType[C <: Z, Z <: AnyRef](zuper : RefType[Z]) extends RefType[C]; + + + case class FooType() extends ClassType[Foo,AnyRef](ObjectType()); + implicit def typeOfFoo = FooType(); + + case class BarType[T3 <: Foo](tpeT : RefType[T3]) extends ClassType[Bar[T3],Foo](FooType); + implicit def typeOfBar[T4 <: Foo](implicit elem : RefType[T4]) : RefType[Bar[T4]] = + BarType(elem); + + + class Foo[A <: AnyRef]; + class Bar[A <: Foo](implicit tpeA : Type[A]) extends Foo; +} diff --git a/tests/untried/neg-with-implicits/t6931/Macros_1.scala b/tests/untried/neg-with-implicits/t6931/Macros_1.scala new file mode 100644 index 000000000..9e167e61d --- /dev/null +++ b/tests/untried/neg-with-implicits/t6931/Macros_1.scala @@ -0,0 +1,15 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + implicit class Error(ctx: StringContext) { + def err(args: Any*): Unit = macro impl + } + + def impl(c: Context)(args: c.Tree*): c.Tree = { + import c.universe._ + val q"Macros.Error(scala.StringContext.apply($arg)).err()" = c.macroApplication + for (i <- 1 to 3) c.error(arg.pos.withPoint(arg.pos.point + i - 1), i.toString) + q"()" + } +} diff --git a/tests/untried/neg-with-implicits/t6931/Test_2.scala b/tests/untried/neg-with-implicits/t6931/Test_2.scala new file mode 100644 index 000000000..dbd7fc260 --- /dev/null +++ b/tests/untried/neg-with-implicits/t6931/Test_2.scala @@ -0,0 +1,4 @@ +object Test extends App { + import Macros._ + err"123" +} diff --git a/tests/untried/neg-with-implicits/t696.scala b/tests/untried/neg-with-implicits/t696.scala new file mode 100644 index 000000000..ca76f7ef6 --- /dev/null +++ b/tests/untried/neg-with-implicits/t696.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/tests/untried/neg-with-implicits/t712.scala b/tests/untried/neg-with-implicits/t712.scala new file mode 100644 index 000000000..6f2627743 --- /dev/null +++ b/tests/untried/neg-with-implicits/t712.scala @@ -0,0 +1,19 @@ +trait A { + type Node <: NodeImpl; + implicit def coerce(n : NodeImpl) = n.self; + trait NodeImpl { + def self : Node; + } +} +trait B extends A { + type Parent <: ParentImpl; + implicit def coerce(p : ParentImpl) = p.self; + trait ParentImpl; + type Symbol; + trait SymbolImpl { + def scope : Int; + } + implicit def coerceSym(sym : Symbol) : SymbolImpl; + var s : Symbol = _; + val s_scope = s.scope; +} diff --git a/tests/untried/neg-with-implicits/t7289.scala b/tests/untried/neg-with-implicits/t7289.scala new file mode 100644 index 000000000..ad9340055 --- /dev/null +++ b/tests/untried/neg-with-implicits/t7289.scala @@ -0,0 +1,39 @@ +object Test extends App { + trait Schtroumpf[T] + + implicit def schtroumpf[T, U <: Coll[T], Coll[X] <: Traversable[X]] + (implicit minorSchtroumpf: Schtroumpf[T]): Schtroumpf[U] = ??? + + implicit val qoo: Schtroumpf[Int] = new Schtroumpf[Int]{} + implicitly[Schtroumpf[Nil.type]] +} + +/* +info1 = {scala.tools.nsc.typechecker.Implicits$ImplicitInfo@3468}"qoo: => Test.Schtroumpf[Int]" +info2 = {scala.tools.nsc.typechecker.Implicits$ImplicitInfo@3469}"schtroumpf: [T, U <: Coll[T], Coll[_] <: Traversable[_]](implicit minorSchtroumpf: Test.Schtroumpf[T])Test.Schtroumpf[U]" +isStrictlyMoreSpecific(info1, info2) + isSubType(Test.Schtroumpf[Int], Test.Schtroumpf[U] forSome { T; U <: Coll[T]; Coll[_] <: Traversable[_] }) + isAsSpecificValueType(Test.Schtroumpf[Int], Test.Schtroumpf[U], undef2 = List(type T, type U, type Coll)) + + val et: ExistentialType = Test.Schtroumpf[U] forSome { T; U <: Coll[T]; Coll[_] <: Traversable[_] } + val tp1 = Test.Schtroumpf[Int] + et.withTypeVars(isSubType(tp1, _, depth)) + solve() + tvars = tList(=?Nothing, =?Int, =?=?Int) + + +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) +[ setInst] scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=scala.collection.immutable.Nil.type ) +[ setInst] =?scala.collection.immutable.Nil.type( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?scala.collection.immutable.Nil.type ) +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Int ) +[ create] ?T ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?U ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ create] ?Coll ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]] ) +[ setInst] Nothing ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], T=Nothing ) +[ setInst] Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], U=Int ) +[ setInst] =?Int ( In Test#schtroumpf[T,U <: Coll[T],Coll[_] <: Traversable[_]], Coll==?Int ) +*/ diff --git a/tests/untried/neg-with-implicits/t7289_status_quo.scala b/tests/untried/neg-with-implicits/t7289_status_quo.scala new file mode 100644 index 000000000..e1f9a9f8a --- /dev/null +++ b/tests/untried/neg-with-implicits/t7289_status_quo.scala @@ -0,0 +1,23 @@ +// record the status quo after this fix +// not clear to @adriaanm why an upper-bounded existential in an invariant position +// is different from putting that upper bound in a covariant position +object Test1 { + trait Ext[T] + implicit def f[A, Coll <: CC[A], CC[X] <: Traversable[X]](implicit xi: Ext[A]): Ext[Coll] = ??? + implicit val m: Ext[List[List[Int]]] = new Ext[List[List[Int]]]{} + + implicitly[Ext[List[Int]]] // fails - not found + implicitly[Ext[List[List[Int]]]] // compiles + implicitly[Ext[List[List[List[Int]]]]] // fails - not found + + // Making Ext[+T] should incur the same behavior as these. (so says @paulp) + implicitly[Ext[_ <: List[Int]]] // compiles + implicitly[Ext[_ <: List[List[Int]]]] // fails - ambiguous + implicitly[Ext[_ <: List[List[List[Int]]]]] // compiles + + // But, we currently get: + trait ExtCov[+T] + implicitly[ExtCov[List[Int]]] // fails - not found + implicitly[ExtCov[List[List[Int]]]] // fails - not found + implicitly[ExtCov[List[List[List[Int]]]]] // fails - not found +} diff --git a/tests/untried/neg-with-implicits/t729.scala b/tests/untried/neg-with-implicits/t729.scala new file mode 100644 index 000000000..83e7f4cd1 --- /dev/null +++ b/tests/untried/neg-with-implicits/t729.scala @@ -0,0 +1,23 @@ +trait Parser { + type Node <: NodeImpl; + implicit def coerce(n : NodeImpl) = n.self; + trait NodeImpl { + def self : Node; + } + trait Link { + def from : NodeImpl; + } +} + +trait ScalaParserAutoEdit extends Parser { + type Node <: NodeImpl; + implicit def coerce(node : NodeImpl) = node.self; + trait NodeImpl extends super[Parser].NodeImpl { + def self : Node; + def foo = { + var link : Link = null; + val xxx : NodeImpl = coerce(link.from); + val yyy : NodeImpl = link.from; + } + } +} diff --git a/tests/untried/neg-with-implicits/t7509.scala b/tests/untried/neg-with-implicits/t7509.scala new file mode 100644 index 000000000..3cba801ea --- /dev/null +++ b/tests/untried/neg-with-implicits/t7509.scala @@ -0,0 +1,4 @@ +object NMWE { + def crash[R <: AnyRef](f: R)(implicit ev: R): Any = ??? + crash(42) +} diff --git a/tests/untried/neg-with-implicits/t7519-b/Mac_1.scala b/tests/untried/neg-with-implicits/t7519-b/Mac_1.scala new file mode 100644 index 000000000..55b583d24 --- /dev/null +++ b/tests/untried/neg-with-implicits/t7519-b/Mac_1.scala @@ -0,0 +1,14 @@ +// get expected error message without package declaration +package ex + +import scala.language.experimental.macros +import scala.reflect.macros._ + +object IW { + def foo(a: String): String = ??? +} +object Mac { + def mac(s: String): String = macro macImpl + def macImpl(c: Context)(s: c.Expr[String]): c.Expr[String] = + c.universe.reify(IW.foo(s.splice)) +} diff --git a/tests/untried/neg-with-implicits/t7519-b/Use_2.scala b/tests/untried/neg-with-implicits/t7519-b/Use_2.scala new file mode 100644 index 000000000..0d63eeed5 --- /dev/null +++ b/tests/untried/neg-with-implicits/t7519-b/Use_2.scala @@ -0,0 +1,10 @@ +import scala.language.implicitConversions + +trait Q +trait K + +object Use { + implicit def cd[T](p: T)(implicit ev: T => K): Q = ??? + val x: Q = ex.Mac.mac("asdf") +} + diff --git a/tests/untried/neg-with-implicits/t7519.scala b/tests/untried/neg-with-implicits/t7519.scala new file mode 100644 index 000000000..aea0f35d8 --- /dev/null +++ b/tests/untried/neg-with-implicits/t7519.scala @@ -0,0 +1,18 @@ +class C { + implicit def conversion(m: Int)(implicit nada: Nothing): String = ??? + + class C { // rename class to get correct error, can't find implicit: Nothing. + locally(0 : String) // was: "value conversion is not a member of C.this.C" + } +} + +object Test2 { + trait T; trait U + new T { + implicit def conversion(m: Int)(implicit nada: Nothing): String = ??? + + new U { // nested anonymous classes also share a name. + locally(0 : String) // was: "value conversion is not a member of U" + } + } +} diff --git a/tests/untried/neg-with-implicits/t7721.scala b/tests/untried/neg-with-implicits/t7721.scala new file mode 100644 index 000000000..9ac7b60f0 --- /dev/null +++ b/tests/untried/neg-with-implicits/t7721.scala @@ -0,0 +1,140 @@ +import scala.language.reflectiveCalls + +trait A { + trait Concrete { def conco: Int = 1 } + type Foo <: { def bippy: Int } + type Bar <: { def barry: Int } + + implicit def barTag: scala.reflect.ClassTag[Bar] + + def f1(x: Any) = x match { + case x: Foo with Concrete => x.bippy + x.conco + case _ => -1 + } + def f2(x: Any) = x match { + case x: Concrete with Foo => x.bippy + x.conco + case _ => -1 + } + def f3(x: Any) = x match { + case x: Foo with Bar => x.bippy + x.barry + case _ => -1 + } + def f4(x: Any) = x match { + case x: (Foo @unchecked) => x.bippy // warns, suppressed + case _ => -1 + } + def f5(x: Any) = x match { + case x: (Bar @unchecked) => x.barry // warns (but about the "outer reference"), suppressed + case _ => -1 + } +} + +trait B extends A { + type Foo <: { def bippy: Int ; def dingo: Int } + type Bar <: { def barry: Int ; def bongo: Int } + + override implicit def barTag: scala.reflect.ClassTag[Bar] + + override def f1(x: Any) = x match { + case x: Foo with Concrete => x.bippy + x.dingo + x.conco + case _ => -1 + } + override def f2(x: Any) = x match { + case x: Concrete with Foo => x.bippy + x.dingo + x.conco + case _ => -1 + } + override def f3(x: Any) = x match { + case x: Foo with Bar with Concrete => x.bippy + x.barry + x.dingo + x.conco + x.bongo + case _ => -1 + } + override def f4(x: Any) = x match { + case x: (Foo @unchecked) => x.bippy + x.dingo // warns, suppressed + case _ => -1 + } + override def f5(x: Any) = x match { + case x: (Bar @unchecked) => x.barry + x.bongo // warns (but about the "outer reference"), suppressed + case _ => -1 + } +} + +object Test { + abstract class Base extends A { + trait Foo { + def bippy = 2 + def dingo = 3 + } + trait Bar { + def barry = 2 + def bongo = 3 + } + implicit def barTag: scala.reflect.ClassTag[Bar] = scala.reflect.ClassTag(classOf[Bar]) + + def run(): Unit = { + println("f1") + wrap(f1(new Concrete {})) + wrap(f1(new Foo {})) + wrap(f1(new Bar {})) + wrap(f1(new Foo with Concrete {})) + wrap(f1(new Concrete with Foo {})) + + println("\nf2") + wrap(f2(new Concrete {})) + wrap(f2(new Foo {})) + wrap(f2(new Bar {})) + wrap(f2(new Foo with Concrete {})) + wrap(f2(new Concrete with Foo {})) + wrap(f2(new Bar with Concrete {})) + wrap(f2(new Concrete with Bar {})) + wrap(f2(new Concrete with Foo with Bar {})) + wrap(f2(new Foo with Bar with Concrete {})) + + println("\nf3") + wrap(f3(new Concrete {})) + wrap(f3(new Foo {})) + wrap(f3(new Bar {})) + wrap(f3(new Foo with Concrete {})) + wrap(f3(new Concrete with Foo {})) + wrap(f3(new Bar with Concrete {})) + wrap(f3(new Concrete with Bar {})) + wrap(f3(new Concrete with Foo with Bar {})) + wrap(f3(new Foo with Bar with Concrete {})) + + println("\nf4") + wrap(f4(new Concrete {})) + wrap(f4(new Foo {})) + wrap(f4(new Bar {})) + wrap(f4(new Foo with Concrete {})) + wrap(f4(new Concrete with Foo {})) + wrap(f4(new Bar with Concrete {})) + wrap(f4(new Concrete with Bar {})) + wrap(f4(new Concrete with Foo with Bar {})) + wrap(f4(new Foo with Bar with Concrete {})) + + println("\nf5") + wrap(f5(new Concrete {})) + wrap(f5(new Foo {})) + wrap(f5(new Bar {})) + wrap(f5(new Foo with Concrete {})) + wrap(f5(new Concrete with Foo {})) + wrap(f5(new Bar with Concrete {})) + wrap(f5(new Concrete with Bar {})) + wrap(f5(new Concrete with Foo with Bar {})) + wrap(f5(new Foo with Bar with Concrete {})) + } + } + + object ao extends Base + object bo extends Base with B + + private def wrap(body: => Any): Unit = { + try println(body) + catch { case ex: NoSuchMethodException => println(ex) } + } + + def main(args: Array[String]): Unit = { + ao.run() + bo.run() + } +} + +// java.lang.NoSuchMethodException: Test$$anon$1.bippy() diff --git a/tests/untried/neg-with-implicits/t8024.scala b/tests/untried/neg-with-implicits/t8024.scala new file mode 100644 index 000000000..b4c2c5ebb --- /dev/null +++ b/tests/untried/neg-with-implicits/t8024.scala @@ -0,0 +1,14 @@ +package p + +trait NRoot[A] + +object `package` { + final def sqrt(x: Double): Double = Math.sqrt(x) + final def sqrt[A](a: A)(implicit ev: NRoot[A]): A = ??? +} + +object FastComplex { + import java.lang.Math.sqrt + + sqrt(0d) +} diff --git a/tests/untried/neg-with-implicits/t8024b.scala b/tests/untried/neg-with-implicits/t8024b.scala new file mode 100644 index 000000000..cf3d49636 --- /dev/null +++ b/tests/untried/neg-with-implicits/t8024b.scala @@ -0,0 +1,17 @@ +package p + +trait NRoot[A] + +object FastComplex { + final def sqrt(x: Double): Double = Math.sqrt(x) + final def sqrt[A](a: A)(implicit ev: NRoot[A]): A = ??? + + object Inner { + import java.lang.Math.sqrt + + // wrong message: + // error: reference to sqrt is ambiguous; + // it is both defined in object FastComplex and imported subsequently by + sqrt(0d) + } +} diff --git a/tests/untried/neg-with-implicits/t8104/Macros_1.scala b/tests/untried/neg-with-implicits/t8104/Macros_1.scala new file mode 100644 index 000000000..129c8db16 --- /dev/null +++ b/tests/untried/neg-with-implicits/t8104/Macros_1.scala @@ -0,0 +1,11 @@ +import scala.reflect.macros.whitebox.Context + +object Macros { + def impl[T](c: Context)(implicit T: c.WeakTypeTag[T]) = { + import c.universe._ + import definitions._ + val fields = T.tpe.decls.toList.collect{ case x: TermSymbol if x.isVal && x.isCaseAccessor => x } + val Repr = appliedType(TupleClass(fields.length).asType.toType, fields.map(_.info)) + q"new Generic[$T]{ type Repr = $Repr }" + } +} diff --git a/tests/untried/neg-with-implicits/t8104/Test_2.scala b/tests/untried/neg-with-implicits/t8104/Test_2.scala new file mode 100644 index 000000000..a3bd94018 --- /dev/null +++ b/tests/untried/neg-with-implicits/t8104/Test_2.scala @@ -0,0 +1,21 @@ +trait Generic[T] { type Repr } +object Generic { + type Aux[T, Repr0] = Generic[T] { type Repr = Repr0 } + import scala.language.experimental.macros + implicit def materializeGeneric[T]: Generic[T] = macro Macros.impl[T] +} + +object Test extends App { + case class C(x: Int, y: Int) + + import scala.reflect.runtime.universe._ + def reprify[T, Repr](x: T)(implicit generic: Generic.Aux[T, Repr], tag: WeakTypeTag[Repr]) = println(tag) + reprify(C(40, 2)) + + // this is a compilation error at the moment as explained in SI-8104 + // because matchesPt in implicit search says that depoly() isn't a subtype of Generic.Aux[C, (Int, Int)] + // which is rightfully so, because depoly only replaces type parameters, not type members with wildcard types + // however in the future we might want to relax the matchesPt check, so this might start compiling + // therefore, if you've broken this test, then you should be happy, because most likely you've just enabled an interesting use case! + implicitly[Generic.Aux[C, (Int, Int)]] +} diff --git a/tests/untried/neg-with-implicits/t8372.scala b/tests/untried/neg-with-implicits/t8372.scala new file mode 100644 index 000000000..60a674f4d --- /dev/null +++ b/tests/untried/neg-with-implicits/t8372.scala @@ -0,0 +1,10 @@ +class t8372 { + // failed with "error: tpe T1 is an unresolved spliceable type"; that was caused by + // misguided type inference of type parameters in ArrayOps.unzip + // the type inference failed because the order of implicit arguments was wrong + // the evidence that T <: (T1, T2) came as last argument so it couldn't guide the + // type inference early enough + def unzip[T1, T2](a: Array[(T1, T2)]) = a.unzip + // the same as above + def unzip3[T1, T2, T3](a: Array[(T1, T2, T3)]): (Array[T1], Array[T2], Array[T3]) = a.unzip3 +} diff --git a/tests/untried/neg-with-implicits/viewtest.scala b/tests/untried/neg-with-implicits/viewtest.scala new file mode 100644 index 000000000..5e7d624d2 --- /dev/null +++ b/tests/untried/neg-with-implicits/viewtest.scala @@ -0,0 +1,116 @@ +package test + +/** A trait for totally ordered data. + */ +trait Ordered[+a] { + + /** Result of comparing `this' with operand `that'. + * returns `x' where + * x < 0 iff this < that + * x == 0 iff this == that + * x > 0 iff this > that + */ + def compareTo [b >: a <% Ordered[b]](that: b): Int + + def < [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) < 0 + + def > [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) > 0 + + def <= [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) <= 0 + + def >= [b >: a <% Ordered[b]](that: b): Boolean = (this compareTo that) >= 0 +} + + +object O { + + implicit def view1(x: String): Ordered[String] = new Ordered[String] { + def compareTo [b >: String <% Ordered[b]](y: b): Int = y match { + case y1: String => x compareTo y1 + case _ => -(y compareTo x) + } + } + implicit def view2(x: Char): Ordered[Char] = new Ordered[Char] { + def compareTo [b >: Char <% Ordered[b]](y: b): Int = y match { + case y1: Char => x - y1 + case _ => -(y compareTo x) + } + } + + implicit def view3[a <% Ordered[a]](x: List[a]): Ordered[List[a]] = + new Ordered[List[a]] { + def compareTo [b >: List[a] <% Ordered[b]](y: b): Int = y match { + case y1: List[a] => compareLists(x, y1) + case _ => -(y compareTo x) + } + private def compareLists(xs: List[a], ys: List[a]): Int = { + if (xs.isEmpty && ys.isEmpty) 0 + else if (xs.isEmpty) -1 + else if (ys.isEmpty) 1 + else { + val s = xs.head compareTo ys.head + if (s != 0) s + else compareLists(xs.tail, ys.tail) + } + } + } + implicit def view4[a](x: a): a = x +} + +abstract class Tree[+a <% Ordered[a]] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] + def elements: List[a] +} + +object Empty extends Tree[Nothing] { + def insert[b >: Nothing <% Ordered[b]](x: b): Tree[b] = new Node(x, Empty, Empty) + def elements: List[Nothing] = List() +} + +class Node[a <% Ordered[a]](elem: a, l: Tree[a], r: Tree[a]) extends Tree[a] { + def insert[b >: a <% Ordered[b]](x: b): Tree[b] = + if (x == elem) this + else if (x < elem) new Node(elem, l insert x, r) + else new Node(elem, l, r insert x) + def elements: List[a] = + l.elements ::: List(elem) ::: r.elements +} + +case class Str(elem: String) extends Ordered[Str] { + def compareTo[b >: Str <% Ordered[b]](that: b): Int = that match { + case that1: Str => this.elem compareTo that1.elem + case _ => -(that compareTo this) + } +} + +object Test { + import O._ + + private def toCharList(s: String): List[Char] = + if (s.length() == 0) List() + else s.charAt(0) :: toCharList(s.substring(1)) + + def main(args: Array[String]) = { + { + var t: Tree[String] = Empty + for (s <- args) { + t = t insert s + } + Console.println(t.elements) + } + { + var t: Tree[Str] = Empty + for (s <- args) { + t = t insert Str(s) + } + Console.println(t.elements) + } + { + var t: Tree[List[Char]] = Empty + for (s <- args) { + t = t insert toCharList(s) + } + Console.println(t.elements) + } + } +} diff --git a/tests/untried/neg-with-implicits/warn-unused-imports.scala b/tests/untried/neg-with-implicits/warn-unused-imports.scala new file mode 100644 index 000000000..b7a2f1c41 --- /dev/null +++ b/tests/untried/neg-with-implicits/warn-unused-imports.scala @@ -0,0 +1,125 @@ +class Bippo { + def length: Int = 123 + class Tree +} + +package object p1 { + class A + implicit class B(val s: String) { def bippy = s } + val c: Bippo = new Bippo + type D = String +} +package object p2 { + class A + implicit class B(val s: String) { def bippy = s } + val c: Bippo = new Bippo + type D = Int +} + +trait NoWarn { + { + import p1._ // no warn + println("abc".bippy) + } + + { + import p1._ // no warn + println(new A) + } + + { + import p1.B // no warn + println("abc".bippy) + } + + { + import p1._ // no warn + import c._ // no warn + println(length) + } + + { + import p1._ // no warn + import c._ // no warn + val x: Tree = null + println(x) + } + + { + import p1.D // no warn + val x: D = null + println(x) + } +} + +trait Warn { + { + import p1.A // warn + println(123) + } + + { + import p1.{ A, B } // warn on A + println("abc".bippy) + } + + { + import p1.{ A, B } // warn on both + println(123) + } + + { + import p1._ // no warn (technically this could warn, but not worth the effort to unroll unusedness transitively) + import c._ // warn + println(123) + } + + { + import p1._ // warn + println(123) + } + + { + class Tree + import p1._ // no warn + import c._ // warn + val x: Tree = null + println(x) + } + + { + import p1.c._ // warn + println(123) + } +} + +trait Nested { + { + import p1._ // warn + trait Warn { // warn about unused local trait for good measure + import p2._ + println(new A) + println("abc".bippy) + } + println("") + } + + { + import p1._ // no warn + trait NoWarn { + import p2.B // no warn + println("abc".bippy) + println(new A) + } + println(new NoWarn { }) + } + + { + import p1.A // warn + trait Warn { + import p2.A + println(new A) + } + println(new Warn { }) + } +} -- cgit v1.2.3