diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-08 16:05:05 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-07-08 16:05:05 -0700 |
commit | 72863241ead712ace45071a21b84288959f6ce53 (patch) | |
tree | 2dc6ad982cc7cac0955042f9da9cf59568ee81df /test/files/run | |
parent | 9e064f783e7ee42b9d27655e2b15d830f8bae5f0 (diff) | |
parent | ede32ba3421be657a4369b847e60d5fb2b9def14 (diff) | |
download | scala-72863241ead712ace45071a21b84288959f6ce53.tar.gz scala-72863241ead712ace45071a21b84288959f6ce53.tar.bz2 scala-72863241ead712ace45071a21b84288959f6ce53.zip |
Merge pull request #2650 from paulp/issue/6221
SI-6221 inference with Function1 subtypes.
Diffstat (limited to 'test/files/run')
-rw-r--r-- | test/files/run/t6221.check | 1 | ||||
-rw-r--r-- | test/files/run/t6221/Macros_1.scala | 22 | ||||
-rw-r--r-- | test/files/run/t6221/Test_2.scala | 10 |
3 files changed, 33 insertions, 0 deletions
diff --git a/test/files/run/t6221.check b/test/files/run/t6221.check new file mode 100644 index 0000000000..aa1bdd0e6e --- /dev/null +++ b/test/files/run/t6221.check @@ -0,0 +1 @@ +((x) => x.$percent(2).$eq$eq(0)) diff --git a/test/files/run/t6221/Macros_1.scala b/test/files/run/t6221/Macros_1.scala new file mode 100644 index 0000000000..c9500626d8 --- /dev/null +++ b/test/files/run/t6221/Macros_1.scala @@ -0,0 +1,22 @@ +import language.experimental.macros +import language.implicitConversions +import scala.reflect.macros.Context +import scala.reflect.runtime.universe.Tree + +class ReflectiveClosure[A, B](val tree: Tree, fn: A => B) extends (A => B) { + def apply(x: A) = fn(x) +} + +object ReflectiveClosure { + implicit def reflectClosure[A, B](f: A => B): ReflectiveClosure[A, B] = macro Macros.reflectiveClosureImpl[A, B] +} + +object Macros { + def reflectiveClosureImpl[A, B](c: Context)(f: c.Expr[A => B]): c.Expr[ReflectiveClosure[A, B]] = { + import c.universe._ + val u = treeBuild.mkRuntimeUniverseRef + val m = EmptyTree + val tree = c.Expr[scala.reflect.runtime.universe.Tree](Select(c.reifyTree(u, m, f.tree), newTermName("tree"))) + c.universe.reify(new ReflectiveClosure(tree.splice, f.splice)) + } +} diff --git a/test/files/run/t6221/Test_2.scala b/test/files/run/t6221/Test_2.scala new file mode 100644 index 0000000000..9f6b2280a7 --- /dev/null +++ b/test/files/run/t6221/Test_2.scala @@ -0,0 +1,10 @@ +object Test extends App { + implicit class PimpedList[T](val list: List[T]) { + def query(predicate: ReflectiveClosure[T, Boolean]): List[T] = { + println(predicate.tree) + list filter predicate + } + } + + List(1, 2, 3).query(x => x % 2 == 0) +}
\ No newline at end of file |