summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-10-23 05:40:52 -0700
committerJason Zaugg <jzaugg@gmail.com>2013-10-23 05:40:52 -0700
commit1021a38979b2264442112c13bcf4538d22c661c1 (patch)
tree58e93fb5393ece780b57e84bdf5edbdee685da45 /src
parent3bfc12a7c2369fe666ca2576ac7af8cdc91451ab (diff)
parent9b6a269b6af0da9a89d39578402bed82c47f4ab7 (diff)
downloadscala-1021a38979b2264442112c13bcf4538d22c661c1.tar.gz
scala-1021a38979b2264442112c13bcf4538d22c661c1.tar.bz2
scala-1021a38979b2264442112c13bcf4538d22c661c1.zip
Merge pull request #3070 from xeno-by/topic/macro-impl-wrong-shape
better macro impl shape errors
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/macros/compiler/Errors.scala21
-rw-r--r--src/compiler/scala/reflect/macros/util/Helpers.scala7
2 files changed, 20 insertions, 8 deletions
diff --git a/src/compiler/scala/reflect/macros/compiler/Errors.scala b/src/compiler/scala/reflect/macros/compiler/Errors.scala
index 9b56e417e2..45bb87fc47 100644
--- a/src/compiler/scala/reflect/macros/compiler/Errors.scala
+++ b/src/compiler/scala/reflect/macros/compiler/Errors.scala
@@ -44,14 +44,18 @@ trait Errors extends Traces {
message + suffix
}
- private def abbreviateCoreAliases(s: String): String = List("WeakTypeTag", "Expr").foldLeft(s)((res, x) => res.replace("c.universe." + x, "c." + x))
+ private def abbreviateCoreAliases(s: String): String = {
+ val coreAliases = List("WeakTypeTag", "Expr", "Tree")
+ coreAliases.foldLeft(s)((res, x) => res.replace("c.universe." + x, "c." + x))
+ }
- private def showMeth(pss: List[List[Symbol]], restpe: Type, abbreviate: Boolean) = {
- var argsPart = (pss map (ps => ps map (_.defString) mkString ("(", ", ", ")"))).mkString
- if (abbreviate) argsPart = abbreviateCoreAliases(argsPart)
- var retPart = restpe.toString
+ private def showMeth(pss: List[List[Symbol]], restpe: Type, abbreviate: Boolean, untype: Boolean) = {
+ def preprocess(tpe: Type) = if (untype) untypeMetalevel(tpe) else tpe
+ var pssPart = (pss map (ps => ps map (p => p.defStringSeenAs(preprocess(p.info))) mkString ("(", ", ", ")"))).mkString
+ if (abbreviate) pssPart = abbreviateCoreAliases(pssPart)
+ var retPart = preprocess(restpe).toString
if (abbreviate || macroDdef.tpt.tpe == null) retPart = abbreviateCoreAliases(retPart)
- argsPart + ": " + retPart
+ pssPart + ": " + retPart
}
// not exactly an error generator, but very related
@@ -86,8 +90,9 @@ trait Errors extends Traces {
private def compatibilityError(message: String) =
implRefError(
"macro implementation has wrong shape:"+
- "\n required: " + showMeth(rparamss, rret, abbreviate = true) +
- "\n found : " + showMeth(aparamss, aret, abbreviate = false) +
+ "\n required: " + showMeth(rparamss, rret, abbreviate = true, untype = false) +
+ "\n or : " + showMeth(rparamss, rret, abbreviate = true, untype = true) +
+ "\n found : " + showMeth(aparamss, aret, abbreviate = false, untype = false) +
"\n" + message)
def MacroImplNonTagImplicitParameters(params: List[Symbol]) = compatibilityError("macro implementations cannot have implicit parameters other than WeakTypeTag evidences")
diff --git a/src/compiler/scala/reflect/macros/util/Helpers.scala b/src/compiler/scala/reflect/macros/util/Helpers.scala
index f40c6bb7e6..dd23b0fc32 100644
--- a/src/compiler/scala/reflect/macros/util/Helpers.scala
+++ b/src/compiler/scala/reflect/macros/util/Helpers.scala
@@ -55,6 +55,13 @@ trait Helpers {
case tp => typeRef(pre, MacroContextExprClass, List(tp))
}
+ /** Transforms c.Expr[T] types into c.Tree and leaves the rest unchanged.
+ */
+ def untypeMetalevel(tp: Type): Type = transparentShallowTransform(RepeatedParamClass, tp) {
+ case ExprClassOf(_) => typeRef(tp.prefix, TreesTreeType, Nil)
+ case tp => tp
+ }
+
/** Decreases metalevel of the type, i.e. transforms:
* * c.Expr[T] to T
* * Anything else to Any