summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-07-12 11:57:39 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-07-12 11:57:39 -0700
commite9fbdb22c94cd3ab7c4d297c6e9c61fc86263b4c (patch)
tree108c5081b02923a2f8889afc1f02673f09ef64dc /src/reflect
parent69901bf25d5a83d6b7bc002b76e69a1a8d38546b (diff)
parente72ae708ed39ad006ef7dbbb85e116a8e6704663 (diff)
downloadscala-e9fbdb22c94cd3ab7c4d297c6e9c61fc86263b4c.tar.gz
scala-e9fbdb22c94cd3ab7c4d297c6e9c61fc86263b4c.tar.bz2
scala-e9fbdb22c94cd3ab7c4d297c6e9c61fc86263b4c.zip
Merge pull request #2689 from scalamacros/ticket/7617
SI-7617 typedAssign no longer expands lhs
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/StdAttachments.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/StdAttachments.scala b/src/reflect/scala/reflect/internal/StdAttachments.scala
index b782353ed3..539d19140c 100644
--- a/src/reflect/scala/reflect/internal/StdAttachments.scala
+++ b/src/reflect/scala/reflect/internal/StdAttachments.scala
@@ -42,4 +42,35 @@ trait StdAttachments {
* (but think thrice before using that API - see the discussion at https://github.com/scala/scala/pull/1639).
*/
case object SuppressMacroExpansionAttachment
+
+ /** Suppresses macro expansion of the tree by putting SuppressMacroExpansionAttachment on it.
+ */
+ def suppressMacroExpansion(tree: Tree) = tree.updateAttachment(SuppressMacroExpansionAttachment)
+
+ /** Unsuppresses macro expansion of the tree by removing SuppressMacroExpansionAttachment from it and its children.
+ */
+ def unsuppressMacroExpansion(tree: Tree): Tree = {
+ tree.removeAttachment[SuppressMacroExpansionAttachment.type]
+ tree match {
+ // see the comment to `isMacroExpansionSuppressed` to learn why we need
+ // a special traversal strategy here
+ case Apply(fn, _) => unsuppressMacroExpansion(fn)
+ case TypeApply(fn, _) => unsuppressMacroExpansion(fn)
+ case _ => // do nothing
+ }
+ tree
+ }
+
+ /** Determines whether a tree should not be expanded, because someone has put SuppressMacroExpansionAttachment on it or one of its children.
+ */
+ def isMacroExpansionSuppressed(tree: Tree): Boolean =
+ if (tree.attachments.get[SuppressMacroExpansionAttachment.type].isDefined) true
+ else tree match {
+ // we have to account for the fact that during typechecking an expandee might become wrapped,
+ // i.e. surrounded by an inferred implicit argument application or by an inferred type argument application.
+ // in that case the expandee itself will no longer be suppressed and we need to look at the core
+ case Apply(fn, _) => isMacroExpansionSuppressed(fn)
+ case TypeApply(fn, _) => isMacroExpansionSuppressed(fn)
+ case _ => false
+ }
}