From a6b81ac12a45866e97d30133c12dee775b93ea39 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Sun, 23 Sep 2012 14:07:22 +0200 Subject: SI-6417 correctly reifies non-value types If we're reifying non-value types (e.g. MethodTypes), we can't use them as type arguments for TypeTag/WeakTypeTag factory methods, otherwise the macro expansion won't typecheck: http://groups.google.com/group/scala-internals/browse_thread/thread/2d7bb85bfcdb2e2 This situation is impossible if one uses only reify and type tags, but c.reifyTree and c.reifyType exposes in the macro API let anyone feed anything into the reifier. Therefore I now check the tpe that is about to be used in TypeApply wrapping TypeTag/WeakTypeTag factory methods and replace it with AnyTpe if it doesn't fit. --- test/files/run/macro-reify-type/Test_2.scala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/files/run/macro-reify-type/Test_2.scala (limited to 'test/files/run/macro-reify-type/Test_2.scala') diff --git a/test/files/run/macro-reify-type/Test_2.scala b/test/files/run/macro-reify-type/Test_2.scala new file mode 100644 index 0000000000..9beaf98681 --- /dev/null +++ b/test/files/run/macro-reify-type/Test_2.scala @@ -0,0 +1,21 @@ +import StaticReflect._ + +object Test extends App { + //println(method[List[Int]]("distinct")) + println(method[List[Int]]("map")) + //val $u: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe; + //val $m: $u.Mirror = scala.reflect.runtime.universe.rootMirror; + //import $u._, $m._, Flag._ + //val tpe = { + // val symdef$B2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTypeName("B"), NoPosition, DEFERRED | PARAM, false); + // val symdef$That2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTypeName("That"), NoPosition, DEFERRED | PARAM, false); + // val symdef$f2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTermName("f"), NoPosition, PARAM, false); + // val symdef$bf2 = build.newNestedSymbol(build.selectTerm(staticClass("scala.collection.TraversableLike"), "map"), newTermName("bf"), NoPosition, IMPLICIT | PARAM, false); + // build.setTypeSignature(symdef$B2, TypeBounds(staticClass("scala.Nothing").asType.toTypeConstructor, staticClass("scala.Any").asType.toTypeConstructor)); + // build.setTypeSignature(symdef$That2, TypeBounds(staticClass("scala.Nothing").asType.toTypeConstructor, staticClass("scala.Any").asType.toTypeConstructor)); + // build.setTypeSignature(symdef$f2, TypeRef(ThisType(staticPackage("scala").asModule.moduleClass), staticClass("scala.Function1"), List(staticClass("scala.Int").asType.toTypeConstructor, TypeRef(NoPrefix, symdef$B2, List())))); + // build.setTypeSignature(symdef$bf2, TypeRef(ThisType(staticPackage("scala.collection.generic").asModule.moduleClass), staticClass("scala.collection.generic.CanBuildFrom"), List(TypeRef(ThisType(staticPackage("scala.collection.immutable").asModule.moduleClass), staticClass("scala.collection.immutable.List"), List(staticClass("scala.Int").asType.toTypeConstructor)), TypeRef(NoPrefix, symdef$B2, List()), TypeRef(NoPrefix, symdef$That2, List())))); + // PolyType(List(symdef$B2, symdef$That2), MethodType(List(symdef$f2), MethodType(List(symdef$bf2), TypeRef(NoPrefix, symdef$That2, List())))) + //} + //println(tpe) +} \ No newline at end of file -- cgit v1.2.3