summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Macros.scala
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/compiler/scala/tools/nsc/typechecker/Macros.scala
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/compiler/scala/tools/nsc/typechecker/Macros.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala12
1 files changed, 4 insertions, 8 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(