summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2012-08-07 16:17:59 +0200
committerEugene Burmako <xeno.by@gmail.com>2012-08-07 20:41:17 +0200
commit788478d3ab7dbb6386932eb8cb58dfcc5ee950b1 (patch)
treebe2c895415ababb27dfda7f533e6ce405125b0af /src
parentd8b35a11d67c2a597f1d93456b341a650b542520 (diff)
downloadscala-788478d3ab7dbb6386932eb8cb58dfcc5ee950b1.tar.gz
scala-788478d3ab7dbb6386932eb8cb58dfcc5ee950b1.tar.bz2
scala-788478d3ab7dbb6386932eb8cb58dfcc5ee950b1.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala12
-rw-r--r--src/compiler/scala/tools/reflect/FastTrack.scala2
-rw-r--r--src/library/scala/reflect/base/Universe.scala4
-rw-r--r--src/reflect/scala/reflect/macros/Infrastructure.scala2
-rw-r--r--src/reflect/scala/reflect/runtime/package.scala2
5 files changed, 9 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index 1381450970..7c5d458fee 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -23,7 +23,7 @@ import java.lang.reflect.{Array => jArray, Method => jMethod}
*
* Then fooBar needs to point to a static method of the following form:
*
- * def fooBar[T: c.TypeTag]
+ * def fooBar[T: c.AbsTypeTag]
* (c: scala.reflect.macros.Context)
* (xs: c.Expr[List[T]])
* : c.Expr[T] = {
@@ -156,7 +156,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
case TypeRef(SingleType(NoPrefix, contextParam), sym, List(tparam)) =>
var wannabe = sym
while (wannabe.isAliasType) wannabe = wannabe.info.typeSymbol
- if (wannabe != definitions.AbsTypeTagClass && wannabe != definitions.TypeTagClass)
+ if (wannabe != definitions.AbsTypeTagClass)
List(param)
else
transform(param, tparam.typeSymbol) map (_ :: Nil) getOrElse Nil
@@ -202,7 +202,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
def abbreviateCoreAliases: String = { // hack!
var result = s
result = result.replace("c.universe.AbsTypeTag", "c.AbsTypeTag")
- result = result.replace("c.universe.TypeTag", "c.TypeTag")
result = result.replace("c.universe.Expr", "c.Expr")
result
}
@@ -440,7 +439,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
// we don't have to do this, but it appears to be more clear than allowing them
val implicitParams = actparamss.flatten filter (_.isImplicit)
if (implicitParams.length > 0) {
- reportError(implicitParams.head.pos, "macro implementations cannot have implicit parameters other than TypeTag evidences")
+ reportError(implicitParams.head.pos, "macro implementations cannot have implicit parameters other than AbsTypeTag evidences")
macroTraceVerbose("macro def failed to satisfy trivial preconditions: ")(macroDef)
}
@@ -854,9 +853,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
param.tpe.typeSymbol match {
case definitions.AbsTypeTagClass =>
// do nothing
- case definitions.TypeTagClass =>
- if (!tpe.isConcrete) context.abort(context.enclosingPosition, "cannot create TypeTag from a type %s having unresolved type parameters".format(tpe))
- // otherwise do nothing
case _ =>
throw new Error("unsupported tpe: " + tpe)
}
@@ -1019,7 +1015,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
)
val forgotten = (
if (sym.isTerm) "splice when splicing this variable into a reifee"
- else "c.TypeTag annotation for this type parameter"
+ else "c.AbsTypeTag annotation for this type parameter"
)
typer.context.error(expandee.pos,
template.replaceAllLiterally("@kind@", sym.name.nameKind).format(
diff --git a/src/compiler/scala/tools/reflect/FastTrack.scala b/src/compiler/scala/tools/reflect/FastTrack.scala
index e093c64c72..f84877cccb 100644
--- a/src/compiler/scala/tools/reflect/FastTrack.scala
+++ b/src/compiler/scala/tools/reflect/FastTrack.scala
@@ -28,7 +28,7 @@ trait FastTrack {
def run(args: List[Any]): Any = {
val c = args(0).asInstanceOf[MacroContext]
val result = expander((c, c.expandee))
- c.Expr[Nothing](result)(c.TypeTag.Nothing)
+ c.Expr[Nothing](result)(c.AbsTypeTag.Nothing)
}
}
diff --git a/src/library/scala/reflect/base/Universe.scala b/src/library/scala/reflect/base/Universe.scala
index 6f37214fa8..f098876c18 100644
--- a/src/library/scala/reflect/base/Universe.scala
+++ b/src/library/scala/reflect/base/Universe.scala
@@ -46,8 +46,8 @@ abstract class Universe extends Symbols
* def macroImpl[T](c: Context) = {
* ...
* // T here is just a type parameter, so the tree produced by reify won't be of much use in a macro expansion
- * // however, if T were annotated with c.TypeTag (which would declare an implicit parameter for macroImpl)
- * // then reification would subtitute T with the TypeTree that was used in a TypeApply of this particular macro invocation
+ * // however, if T were annotated with c.AbsTypeTag (which would declare an implicit parameter for macroImpl)
+ * // then reification would substitute T with the TypeTree that was used in a TypeApply of this particular macro invocation
* val factory = c.reify{ new Queryable[T] }
* ...
* }
diff --git a/src/reflect/scala/reflect/macros/Infrastructure.scala b/src/reflect/scala/reflect/macros/Infrastructure.scala
index 1f1bd160a1..5ae2c08265 100644
--- a/src/reflect/scala/reflect/macros/Infrastructure.scala
+++ b/src/reflect/scala/reflect/macros/Infrastructure.scala
@@ -35,7 +35,7 @@ trait Infrastructure {
*
* def staticEval[T](x: T) = macro staticEval[T]
*
- * def staticEval[T: c.TypeTag](c: Context)(x: c.Expr[T]) = {
+ * def staticEval[T](c: Context)(x: c.Expr[T]) = {
* import scala.reflect.runtime.{universe => ru}
* val mirror = ru.runtimeMirror(c.libraryClassLoader)
* import scala.tools.reflect.ToolBox
diff --git a/src/reflect/scala/reflect/runtime/package.scala b/src/reflect/scala/reflect/runtime/package.scala
index 2cb72d3824..d00094c0c1 100644
--- a/src/reflect/scala/reflect/runtime/package.scala
+++ b/src/reflect/scala/reflect/runtime/package.scala
@@ -19,7 +19,7 @@ package runtime {
if (runtimeClass.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class")
val runtimeUniverse = Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("runtime")), newTermName("universe"))
val currentMirror = Apply(Select(runtimeUniverse, newTermName("runtimeMirror")), List(Select(runtimeClass, newTermName("getClassLoader"))))
- c.Expr[Nothing](currentMirror)(c.TypeTag.Nothing)
+ c.Expr[Nothing](currentMirror)(c.AbsTypeTag.Nothing)
}
}
}