diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-07-10 14:52:45 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-07-10 17:50:47 +0200 |
commit | 114d52b1f8be07a95125397879b170e8496c0c2e (patch) | |
tree | af44d71e1ee4fd9d547150af7018f77ce71f960d /src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | |
parent | aada28f92745b21b1fbed81d8c956d60b5d556b9 (diff) | |
download | scala-114d52b1f8be07a95125397879b170e8496c0c2e.tar.gz scala-114d52b1f8be07a95125397879b170e8496c0c2e.tar.bz2 scala-114d52b1f8be07a95125397879b170e8496c0c2e.zip |
macro impls can now return subtypes of c.Tree
10229316db allowed macro impls to take and return values of type c.Tree
in addition to the usual c.Expr. However it didn't take into account that
it is often useful to return subtypes of trees (e.g. with quasiquotes
that expand into expressions typed as precisely as possible). This patch
fixes that oversight.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index f2a77b4333..81f5545695 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -697,7 +697,7 @@ trait ContextErrors { protected def macroExpansionError(expandee: Tree, msg: String, pos: Position = NoPosition) = { def msgForLog = if (msg != null && (msg contains "exception during macro expansion")) msg.split(EOL).drop(1).headOption.getOrElse("?") else msg macroLogLite("macro expansion has failed: %s".format(msgForLog)) - if (msg != null) context.error(pos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions + if (msg != null) context.error(if (pos.isDefined) pos else expandee.pos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions setError(expandee) throw MacroExpansionException } @@ -782,13 +782,16 @@ trait ContextErrors { } def MacroExpansionHasInvalidTypeError(expandee: Tree, expanded: Any) = { + def isUnaffiliatedExpr = expanded.isInstanceOf[scala.reflect.api.Exprs#Expr[_]] + def isUnaffiliatedTree = expanded.isInstanceOf[scala.reflect.api.Trees#TreeApi] val expected = "expr or tree" - val isPathMismatch = expanded != null && expanded.isInstanceOf[scala.reflect.api.Exprs#Expr[_]] + val actual = if (isUnaffiliatedExpr) "an expr" else if (isUnaffiliatedTree) "a tree" else "unexpected" + val isPathMismatch = expanded != null && (isUnaffiliatedExpr || isUnaffiliatedTree) macroExpansionError(expandee, s"macro must return a compiler-specific $expected; returned value is " + ( if (expanded == null) "null" - else if (isPathMismatch) s" $expected, but it doesn't belong to this compiler" - else " of " + expanded.getClass + else if (isPathMismatch) s"$actual, but it doesn't belong to this compiler's universe" + else "of " + expanded.getClass )) } |