diff options
author | Paul Phillips <paulp@improving.org> | 2013-06-12 04:50:00 -0400 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-06-13 08:49:21 -0400 |
commit | ede32ba3421be657a4369b847e60d5fb2b9def14 (patch) | |
tree | 27245ef1a38020a173e9a816f5087246ffa63ddb /test/files/run/t6221/Macros_1.scala | |
parent | f790662a3eab1e8efce5d4096d0efbae96cf45b4 (diff) | |
download | scala-ede32ba3421be657a4369b847e60d5fb2b9def14.tar.gz scala-ede32ba3421be657a4369b847e60d5fb2b9def14.tar.bz2 scala-ede32ba3421be657a4369b847e60d5fb2b9def14.zip |
SI-6221 inference with Function1 subtypes.
There appears to be no upper bound on the number of places
we have to remove calls to typeSymbol and introduce calls to
baseType. This one was type inference for function parameter
types: worked when expected type was A => B, but not if there
was an implicit conversion from A => B to the expected type.
Diffstat (limited to 'test/files/run/t6221/Macros_1.scala')
-rw-r--r-- | test/files/run/t6221/Macros_1.scala | 22 |
1 files changed, 22 insertions, 0 deletions
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)) + } +} |