Skip to content

Commit 788478d

Browse files
committed
SI-6186 TypeTags no longer supported in macros
The original idea was to support both both TypeTags and ConcreteTypeTags as context bounds on macro implementations. Back then TypeTags were the implied default flavor of type tags. Basically because "TypeTag" is shorter than "ConcreteTypeTag" everyone jumped onto them and used them everywhere. That led to problems, because at that time TypeTags could reify unresolved type parameters ("unresolved" = not having TypeTag annotations for them). This led to a series of creepy errors, when one forgets to add a context bound in the middle of a chain of methods that all pass a type tag around, and then suddenly all the tags turn into pumpkins (because that unlucky method just reifies TypeRef(NoPrefix, <type parameter symbol>, Nil and passes it down the chain). Hence we decided to rename ConcreteTypeTag => TypeTag & TypeTag => AbsTypeTag, which makes a lot of sense from a reflection point of view. Unfortunately this broke macros (in a sense), because now everyone writes TypeTag context bounds on macro implementations, which breaks in trivial situations like: "def foo[T](x: T) = identity_macro(x)" (the type of x is not concrete, so macro expansion will emit an error when trying to materialize the corresponding TypeTag). Now we restore the broken balance by banning TypeTag from macro impls. This forces anyone to use AbsTypeTags, and if someone wants to check the input for presence of abstract types, it's possible to do that manually.
1 parent d8b35a1 commit 788478d

File tree

35 files changed

+69
-73
lines changed

35 files changed

+69
-73
lines changed

src/compiler/scala/tools/nsc/typechecker/Macros.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import java.lang.reflect.{Array => jArray, Method => jMethod}
2323
*
2424
* Then fooBar needs to point to a static method of the following form:
2525
*
26-
* def fooBar[T: c.TypeTag]
26+
* def fooBar[T: c.AbsTypeTag]
2727
* (c: scala.reflect.macros.Context)
2828
* (xs: c.Expr[List[T]])
2929
* : c.Expr[T] = {
@@ -156,7 +156,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
156156
case TypeRef(SingleType(NoPrefix, contextParam), sym, List(tparam)) =>
157157
var wannabe = sym
158158
while (wannabe.isAliasType) wannabe = wannabe.info.typeSymbol
159-
if (wannabe != definitions.AbsTypeTagClass && wannabe != definitions.TypeTagClass)
159+
if (wannabe != definitions.AbsTypeTagClass)
160160
List(param)
161161
else
162162
transform(param, tparam.typeSymbol) map (_ :: Nil) getOrElse Nil
@@ -202,7 +202,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
202202
def abbreviateCoreAliases: String = { // hack!
203203
var result = s
204204
result = result.replace("c.universe.AbsTypeTag", "c.AbsTypeTag")
205-
result = result.replace("c.universe.TypeTag", "c.TypeTag")
206205
result = result.replace("c.universe.Expr", "c.Expr")
207206
result
208207
}
@@ -440,7 +439,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
440439
// we don't have to do this, but it appears to be more clear than allowing them
441440
val implicitParams = actparamss.flatten filter (_.isImplicit)
442441
if (implicitParams.length > 0) {
443-
reportError(implicitParams.head.pos, "macro implementations cannot have implicit parameters other than TypeTag evidences")
442+
reportError(implicitParams.head.pos, "macro implementations cannot have implicit parameters other than AbsTypeTag evidences")
444443
macroTraceVerbose("macro def failed to satisfy trivial preconditions: ")(macroDef)
445444
}
446445

@@ -854,9 +853,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
854853
param.tpe.typeSymbol match {
855854
case definitions.AbsTypeTagClass =>
856855
// do nothing
857-
case definitions.TypeTagClass =>
858-
if (!tpe.isConcrete) context.abort(context.enclosingPosition, "cannot create TypeTag from a type %s having unresolved type parameters".format(tpe))
859-
// otherwise do nothing
860856
case _ =>
861857
throw new Error("unsupported tpe: " + tpe)
862858
}
@@ -1019,7 +1015,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
10191015
)
10201016
val forgotten = (
10211017
if (sym.isTerm) "splice when splicing this variable into a reifee"
1022-
else "c.TypeTag annotation for this type parameter"
1018+
else "c.AbsTypeTag annotation for this type parameter"
10231019
)
10241020
typer.context.error(expandee.pos,
10251021
template.replaceAllLiterally("@kind@", sym.name.nameKind).format(

src/compiler/scala/tools/reflect/FastTrack.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait FastTrack {
2828
def run(args: List[Any]): Any = {
2929
val c = args(0).asInstanceOf[MacroContext]
3030
val result = expander((c, c.expandee))
31-
c.Expr[Nothing](result)(c.TypeTag.Nothing)
31+
c.Expr[Nothing](result)(c.AbsTypeTag.Nothing)
3232
}
3333
}
3434

src/library/scala/reflect/base/Universe.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ abstract class Universe extends Symbols
4646
* def macroImpl[T](c: Context) = {
4747
* ...
4848
* // T here is just a type parameter, so the tree produced by reify won't be of much use in a macro expansion
49-
* // however, if T were annotated with c.TypeTag (which would declare an implicit parameter for macroImpl)
50-
* // then reification would subtitute T with the TypeTree that was used in a TypeApply of this particular macro invocation
49+
* // however, if T were annotated with c.AbsTypeTag (which would declare an implicit parameter for macroImpl)
50+
* // then reification would substitute T with the TypeTree that was used in a TypeApply of this particular macro invocation
5151
* val factory = c.reify{ new Queryable[T] }
5252
* ...
5353
* }

src/reflect/scala/reflect/macros/Infrastructure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ trait Infrastructure {
3535
*
3636
* def staticEval[T](x: T) = macro staticEval[T]
3737
*
38-
* def staticEval[T: c.TypeTag](c: Context)(x: c.Expr[T]) = {
38+
* def staticEval[T](c: Context)(x: c.Expr[T]) = {
3939
* import scala.reflect.runtime.{universe => ru}
4040
* val mirror = ru.runtimeMirror(c.libraryClassLoader)
4141
* import scala.tools.reflect.ToolBox

src/reflect/scala/reflect/runtime/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package runtime {
1919
if (runtimeClass.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class")
2020
val runtimeUniverse = Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("runtime")), newTermName("universe"))
2121
val currentMirror = Apply(Select(runtimeUniverse, newTermName("runtimeMirror")), List(Select(runtimeClass, newTermName("getClassLoader"))))
22-
c.Expr[Nothing](currentMirror)(c.TypeTag.Nothing)
22+
c.Expr[Nothing](currentMirror)(c.AbsTypeTag.Nothing)
2323
}
2424
}
2525
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Impls_1.scala:5: error: macro implementations cannot have implicit parameters other than TypeTag evidences
2-
def foo[U: c.TypeTag: Numeric](c: Ctx) = {
1+
Impls_1.scala:5: error: macro implementations cannot have implicit parameters other than AbsTypeTag evidences
2+
def foo[U: c.AbsTypeTag: Numeric](c: Ctx) = {
33
^
44
one error found

test/files/neg/macro-invalidsig-context-bounds/Impls_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[U: c.TypeTag: Numeric](c: Ctx) = {
5+
def foo[U: c.AbsTypeTag: Numeric](c: Ctx) = {
66
import c.universe._
77
Literal(Constant(42))
88
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Impls_Macros_1.scala:5: error: macro implementations cannot have implicit parameters other than TypeTag evidences
2-
def foo_targs[T, U: c.TypeTag](c: Ctx)(implicit x: c.Expr[Int]) = {
3-
^
1+
Impls_Macros_1.scala:5: error: macro implementations cannot have implicit parameters other than AbsTypeTag evidences
2+
def foo_targs[T, U: c.AbsTypeTag](c: Ctx)(implicit x: c.Expr[Int]) = {
3+
^
44
one error found

test/files/neg/macro-invalidsig-implicit-params/Impls_Macros_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo_targs[T, U: c.TypeTag](c: Ctx)(implicit x: c.Expr[Int]) = {
5+
def foo_targs[T, U: c.AbsTypeTag](c: Ctx)(implicit x: c.Expr[Int]) = {
66
import c.{prefix => prefix}
77
import c.universe._
88
val body = Block(
99
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("invoking foo_targs...")))),
1010
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("type of prefix is: " + prefix.staticType)))),
11-
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("U is: " + implicitly[c.TypeTag[U]].tpe)))),
11+
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("U is: " + implicitly[c.AbsTypeTag[U]].tpe)))),
1212
Literal(Constant(())))
1313
c.Expr[Unit](body)
1414
}

test/files/neg/macro-invalidsig-tparams-notparams-a/Impls_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[U: c.TypeTag](c: Ctx) = ???
5+
def foo[U: c.AbsTypeTag](c: Ctx) = ???
66
}

test/files/neg/macro-invalidsig-tparams-notparams-b/Impls_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[T: c.TypeTag, U: c.TypeTag, V](c: Ctx)(implicit V: c.TypeTag[V]): c.Expr[Unit] = {
6-
println(implicitly[c.TypeTag[T]])
7-
println(implicitly[c.TypeTag[U]])
5+
def foo[T: c.AbsTypeTag, U: c.AbsTypeTag, V](c: Ctx)(implicit V: c.AbsTypeTag[V]): c.Expr[Unit] = {
6+
println(implicitly[c.AbsTypeTag[T]])
7+
println(implicitly[c.AbsTypeTag[U]])
88
println(V)
99
c.literalUnit
1010
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Macros_Test_2.scala:3: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$1: c.TypeTag[T], implicit evidence$2: c.TypeTag[U], implicit V: c.TypeTag[V])c.Expr[Unit]
1+
Macros_Test_2.scala:3: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$1: c.AbsTypeTag[T], implicit evidence$2: c.AbsTypeTag[U], implicit V: c.AbsTypeTag[V])c.Expr[Unit]
22
def foo[V] = macro Impls.foo[V]
33
^
44
one error found

test/files/neg/macro-invalidsig-tparams-notparams-c/Impls_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[T: c.TypeTag, U: c.TypeTag, V](c: Ctx)(implicit V: c.TypeTag[V]): c.Expr[Unit] = {
5+
def foo[T: c.AbsTypeTag, U: c.AbsTypeTag, V](c: Ctx)(implicit V: c.AbsTypeTag[V]): c.Expr[Unit] = {
66
import c.universe._
7-
println(implicitly[c.TypeTag[T]])
8-
println(implicitly[c.TypeTag[U]])
7+
println(implicitly[c.AbsTypeTag[T]])
8+
println(implicitly[c.AbsTypeTag[U]])
99
println(V)
1010
c.literalUnit
1111
}

test/files/pos/t6047.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.io.InputStream
44
object Macros {
55
def unpack[A](input: InputStream): A = macro unpack_impl[A]
66

7-
def unpack_impl[A: c.TypeTag](c: Context)(input: c.Expr[InputStream]): c.Expr[A] = {
7+
def unpack_impl[A: c.AbsTypeTag](c: Context)(input: c.Expr[InputStream]): c.Expr[A] = {
88
import c.universe._
99

1010
def unpackcode(tpe: c.Type): c.Expr[_] = {
@@ -14,7 +14,7 @@ object Macros {
1414
???
1515
}
1616

17-
unpackcode(c.typeOf[A])
17+
unpackcode(implicitly[c.AbsTypeTag[A]].tpe)
1818
???
1919
}
2020
}

test/files/run/macro-def-path-dependent-d/Impls_Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import scala.reflect.api.Universe
55
object Test {
66
def materializeTypeTag[T](u: Universe)(e: T) = macro materializeTypeTag_impl[T]
77

8-
def materializeTypeTag_impl[T: c.TypeTag](c: Context)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ???
8+
def materializeTypeTag_impl[T: c.AbsTypeTag](c: Context)(u: c.Expr[Universe])(e: c.Expr[T]): c.Expr[u.value.TypeTag[T]] = ???
99
}

test/files/run/macro-expand-nullary-generic/Impls_1.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def impl[T: c.TypeTag](c: Ctx) = {
5+
def impl[T: c.AbsTypeTag](c: Ctx) = {
66
import c.universe._
7-
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("it works " + implicitly[c.TypeTag[T]]))))
7+
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("it works " + implicitly[c.AbsTypeTag[T]]))))
88
c.Expr[Unit](body)
99
}
1010

11-
def fooNullary[T: c.TypeTag](c: Ctx) = impl[T](c)
12-
def fooEmpty[T: c.TypeTag](c: Ctx)() = impl[T](c)
13-
def barNullary[T: c.TypeTag](c: Ctx)(x: c.Expr[Int]) = impl[T](c)
14-
def barEmpty[T: c.TypeTag](c: Ctx)(x: c.Expr[Int])() = impl[T](c)
11+
def fooNullary[T: c.AbsTypeTag](c: Ctx) = impl[T](c)
12+
def fooEmpty[T: c.AbsTypeTag](c: Ctx)() = impl[T](c)
13+
def barNullary[T: c.AbsTypeTag](c: Ctx)(x: c.Expr[Int]) = impl[T](c)
14+
def barEmpty[T: c.AbsTypeTag](c: Ctx)(x: c.Expr[Int])() = impl[T](c)
1515
}

test/files/run/macro-expand-tparams-explicit/Impls_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[U: c.TypeTag](c: Ctx) = {
5+
def foo[U: c.AbsTypeTag](c: Ctx) = {
66
import c.universe._
7-
val U = implicitly[c.TypeTag[U]]
7+
val U = implicitly[c.AbsTypeTag[U]]
88
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(U.toString))))
99
c.Expr[Unit](body)
1010
}

test/files/run/macro-expand-tparams-implicit/Impls_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[U: c.TypeTag](c: Ctx)(x: c.Expr[U]) = {
5+
def foo[U: c.AbsTypeTag](c: Ctx)(x: c.Expr[U]) = {
66
import c.universe._
7-
val U = implicitly[c.TypeTag[U]]
7+
val U = implicitly[c.AbsTypeTag[U]]
88
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(U.toString))))
99
c.Expr[Unit](body)
1010
}

test/files/run/macro-expand-tparams-prefix-a/Impls_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[U: c.TypeTag](c: Ctx)(x: c.Expr[U]) = {
5+
def foo[U: c.AbsTypeTag](c: Ctx)(x: c.Expr[U]) = {
66
import c.universe._
7-
val U = implicitly[c.TypeTag[U]]
7+
val U = implicitly[c.AbsTypeTag[U]]
88
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(U.toString))))
99
c.Expr[Unit](body)
1010
}

test/files/run/macro-expand-tparams-prefix-b/Impls_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[T: c.TypeTag, U: c.TypeTag](c: Ctx)(x: c.Expr[U]) = {
5+
def foo[T: c.AbsTypeTag, U: c.AbsTypeTag](c: Ctx)(x: c.Expr[U]) = {
66
import c.universe._
7-
val T = implicitly[c.TypeTag[T]]
8-
val U = implicitly[c.TypeTag[U]]
7+
val T = implicitly[c.AbsTypeTag[T]]
8+
val U = implicitly[c.AbsTypeTag[U]]
99
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(T.toString + " " + U.toString))))
1010
c.Expr[Unit](body)
1111
}

test/files/run/macro-expand-tparams-prefix-c1/Impls_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[T, U: c.TypeTag, V](c: Ctx)(implicit T: c.TypeTag[T], V: c.TypeTag[V]): c.Expr[Unit] = {
5+
def foo[T, U: c.AbsTypeTag, V](c: Ctx)(implicit T: c.AbsTypeTag[T], V: c.AbsTypeTag[V]): c.Expr[Unit] = {
66
import c.universe._
77
c.Expr(Block(List(
88
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(T.toString)))),
9-
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(implicitly[c.TypeTag[U]].toString)))),
9+
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(implicitly[c.AbsTypeTag[U]].toString)))),
1010
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(V.toString))))),
1111
Literal(Constant(()))))
1212
}

test/files/run/macro-expand-tparams-prefix-c2/Impls_Macros_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo[T, U: c.TypeTag, V](c: Ctx)(implicit T: c.TypeTag[T], V: c.TypeTag[V]): c.Expr[Unit] = {
5+
def foo[T, U: c.AbsTypeTag, V](c: Ctx)(implicit T: c.AbsTypeTag[T], V: c.AbsTypeTag[V]): c.Expr[Unit] = {
66
import c.universe._
77
c.Expr(Block(List(
88
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(T.toString)))),
9-
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(implicitly[c.TypeTag[U]].toString)))),
9+
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(implicitly[c.AbsTypeTag[U]].toString)))),
1010
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(V.toString))))),
1111
Literal(Constant(()))))
1212
}

test/files/run/macro-impl-default-params/Impls_Macros_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.{Context => Ctx}
33

44
object Impls {
5-
def foo_targs[T, U: c.TypeTag](c: Ctx = null)(x: c.Expr[Int] = null) = {
5+
def foo_targs[T, U: c.AbsTypeTag](c: Ctx = null)(x: c.Expr[Int] = null) = {
66
import c.{prefix => prefix}
77
import c.universe._
8-
val U = implicitly[c.TypeTag[U]]
8+
val U = implicitly[c.AbsTypeTag[U]]
99
val body = Block(
1010
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("invoking foo_targs...")))),
1111
Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant("type of prefix is: " + prefix.staticType)))),

test/files/run/macro-invalidusage-partialapplication-with-tparams/Impls_Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.reflect.macros.{Context => Ctx}
22

33
object Impls {
4-
def foo[T: c.TypeTag](c: Ctx)(x: c.Expr[T]) = {
4+
def foo[T: c.AbsTypeTag](c: Ctx)(x: c.Expr[T]) = {
55
import c.universe._
66
val body = Apply(Select(Ident(definitions.PredefModule), newTermName("println")), List(Literal(Constant(x.tree.toString))))
77
c.Expr[Unit](body)

test/files/run/macro-reify-freevars/Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package scala.collection.slick
22

33
object QueryableMacros{
4-
def map[T:c.TypeTag, S:c.TypeTag]
4+
def map[T:c.AbsTypeTag, S:c.AbsTypeTag]
55
(c: scala.reflect.macros.Context)
66
(projection: c.Expr[T => S])
77
: c.Expr[scala.collection.slick.Queryable[S]] = {

test/files/run/macro-reify-nested-a/Impls_Macros_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ case class Utils[C <: Context]( c:C ) {
2121
}
2222
}
2323
object QueryableMacros{
24-
def _helper[C <: Context,S:c.TypeTag]( c:C )( name:String, projection:c.Expr[_] ) = {
24+
def _helper[C <: Context,S:c.AbsTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = {
2525
import c.universe._
26-
val element_type = c.typeOf[S]
26+
val element_type = implicitly[c.AbsTypeTag[S]].tpe
2727
val foo = c.Expr[ru.Expr[Queryable[S]]](
2828
c.reifyTree( c.runtimeUniverse, EmptyTree, c.typeCheck(
2929
Utils[c.type](c).removeDoubleReify(
@@ -32,7 +32,7 @@ object QueryableMacros{
3232
)))
3333
c.universe.reify{ Queryable.factory[S]( foo.splice )}
3434
}
35-
def map[T:c.TypeTag, S:c.TypeTag]
35+
def map[T:c.AbsTypeTag, S:c.AbsTypeTag]
3636
(c: scala.reflect.macros.Context)
3737
(projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection )
3838
}

test/files/run/macro-reify-nested-b/Impls_Macros_1.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ case class Utils[C <: Context]( c:C ) {
2121
}
2222
}
2323
object QueryableMacros{
24-
def _helper[C <: Context,S:c.TypeTag]( c:C )( name:String, projection:c.Expr[_] ) = {
24+
def _helper[C <: Context,S:c.AbsTypeTag]( c:C )( name:String, projection:c.Expr[_] ) = {
2525
import c.universe._
26-
val element_type = c.typeOf[S]
26+
val element_type = implicitly[c.AbsTypeTag[S]].tpe
2727
val foo = c.Expr[ru.Expr[Queryable[S]]](
2828
c.reifyTree( c.runtimeUniverse, EmptyTree, c.typeCheck(
2929
Utils[c.type](c).removeDoubleReify(
@@ -32,7 +32,7 @@ object QueryableMacros{
3232
)))
3333
c.universe.reify{ Queryable.factory[S]( foo.splice )}
3434
}
35-
def map[T:c.TypeTag, S:c.TypeTag]
35+
def map[T:c.AbsTypeTag, S:c.AbsTypeTag]
3636
(c: scala.reflect.macros.Context)
3737
(projection: c.Expr[T => S]): c.Expr[Queryable[S]] = _helper[c.type,S]( c )( "_map", projection )
3838
}

test/files/run/macro-reify-tagful-a/Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Macros {
55
def foo[T](s: T) = macro Impls.foo[T]
66

77
object Impls {
8-
def foo[T: c.TypeTag](c: Ctx)(s: c.Expr[T]) = c.universe.reify {
8+
def foo[T: c.AbsTypeTag](c: Ctx)(s: c.Expr[T]) = c.universe.reify {
99
List(s.splice)
1010
}
1111
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
reflective compilation has failed:
2-
3-
Macro expansion contains free type variable T defined by foo in Impls_Macros_1.scala:7:13. Have you forgotten to use c.TypeTag annotation for this type parameter? If you have troubles tracking free type variables, consider using -Xlog-free-types
1+
reflective compilation has failed:
2+
3+
Macro expansion contains free type variable T defined by foo in Impls_Macros_1.scala:7:13. Have you forgotten to use c.AbsTypeTag annotation for this type parameter? If you have troubles tracking free type variables, consider using -Xlog-free-types

test/files/run/macro-undetparams-macroitself/Impls_Macros_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import scala.reflect.runtime.universe._
22
import scala.reflect.macros.Context
33

44
object Macros {
5-
def impl[T: c.TypeTag](c: Context)(foo: c.Expr[T]): c.Expr[Unit] = c.universe.reify { println(c.literal(implicitly[c.TypeTag[T]].toString).splice) }
5+
def impl[T: c.AbsTypeTag](c: Context)(foo: c.Expr[T]): c.Expr[Unit] = c.universe.reify { println(c.literal(implicitly[c.AbsTypeTag[T]].toString).splice) }
66

77
def foo[T](foo: T) = macro impl[T]
88
}

0 commit comments

Comments
 (0)