diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-11-06 16:58:08 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-11-06 17:09:21 +1000 |
commit | 17992f672f7d5663654a1ea365dfd1dad7061410 (patch) | |
tree | df0be801ef2ce2c6679980f6082456ff1b121967 /src | |
parent | d056439a2762b342f66759de654f0dadb01f5e9a (diff) | |
download | scala-17992f672f7d5663654a1ea365dfd1dad7061410.tar.gz scala-17992f672f7d5663654a1ea365dfd1dad7061410.tar.bz2 scala-17992f672f7d5663654a1ea365dfd1dad7061410.zip |
SI-8947 Additional layers of defence against EmptyTree mutation
As suggested in review:
- Use `abort` rather than `{error; EmptyTree} when we hit an
error in reification or tag materialization.
- Explicitly avoid adding the `MacroExpansionAttachment` to the
macro expansion if it an `EmptyTree`
- Emit a `-Xdev` warning if any other code paths find a way to
mutate attachments in places they shouldn't.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/reflect/reify/Taggers.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Trees.scala | 7 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala index 093c2bee22..0863ee38f9 100644 --- a/src/compiler/scala/reflect/reify/Taggers.scala +++ b/src/compiler/scala/reflect/reify/Taggers.scala @@ -79,8 +79,7 @@ abstract class Taggers { try materializer catch { case ReificationException(pos, msg) => - c.error(pos.asInstanceOf[c.Position], msg) // this cast is a very small price for the sanity of exception handling - EmptyTree + c.abort(pos.asInstanceOf[c.Position], msg) // this cast is a very small price for the sanity of exception handling case UnexpectedReificationException(pos, err, cause) if cause != null => throw cause } diff --git a/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala b/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala index 57f27a05fd..ea44b9dc39 100644 --- a/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala +++ b/src/compiler/scala/tools/nsc/typechecker/StdAttachments.scala @@ -61,7 +61,7 @@ trait StdAttachments { val metadata = MacroExpansionAttachment(expandee, expanded) expandee updateAttachment metadata expanded match { - case expanded: Tree => expanded updateAttachment metadata + case expanded: Tree if !expanded.isEmpty => expanded updateAttachment metadata case _ => // do nothing } } diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala index 26e9c7f89d..af533b21bc 100644 --- a/src/reflect/scala/reflect/internal/Trees.scala +++ b/src/reflect/scala/reflect/internal/Trees.scala @@ -1078,9 +1078,10 @@ trait Trees extends api.Trees { // We silently ignore attempts to add attachments to `EmptyTree`. See SI-8947 for an // example of a bug in macro expansion that this solves. - override def setAttachments(attachments: Attachments {type Pos = Position}): this.type = this - override def updateAttachment[T: ClassTag](attachment: T): this.type = this - override def removeAttachment[T: ClassTag]: this.type = this + override def setAttachments(attachments: Attachments {type Pos = Position}): this.type = attachmentWarning() + override def updateAttachment[T: ClassTag](attachment: T): this.type = attachmentWarning() + override def removeAttachment[T: ClassTag]: this.type = attachmentWarning() + private def attachmentWarning(): this.type = {devWarning(s"Attempt to mutate attachments on $self ignored"); this} private def requireLegal(value: Any, allowed: Any, what: String) = ( if (value != allowed) { |