summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-12-10 16:39:31 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-12-17 13:03:08 +0100
commitb275c38c9491a6f7a47be40cb52e2935ca0e2d69 (patch)
tree0207ff8b724803350a071562882180c506cf83c2 /src
parentb345b42cac64aa97e3bbcc6f14ef8f08214ab56f (diff)
downloadscala-b275c38c9491a6f7a47be40cb52e2935ca0e2d69.tar.gz
scala-b275c38c9491a6f7a47be40cb52e2935ca0e2d69.tar.bz2
scala-b275c38c9491a6f7a47be40cb52e2935ca0e2d69.zip
duplicates macro arguments before expansion
As discussed with Jason, this is an important dimension of defenses that we can build to ensure robustness of the macro engine. This commit is important in the context of the upcoming patch to the presentation compiler that will throw away expansions and keep original macro applications (only when run in presentation compiler mode) so that hyperlinking in macro arguments starts working in the IDE. Duplication of macro arguments will make sure that macro arguments, which are going to become exposed to the IDE, can’t become corrupted by possibly misbehaving or misguided macros.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Macros.scala6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
index 27920dbd74..cf5f62574f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala
@@ -345,7 +345,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
new {
val universe: self.global.type = self.global
val callsiteTyper: universe.analyzer.Typer = typer.asInstanceOf[global.analyzer.Typer]
- val expandee = universe.analyzer.macroExpanderAttachment(expandeeTree).original orElse expandeeTree
+ val expandee = universe.analyzer.macroExpanderAttachment(expandeeTree).original orElse duplicateAndKeepPositions(expandeeTree)
val macroRole = universe.analyzer.macroExpanderAttachment(expandeeTree).role
} with UnaffiliatedMacroContext {
val prefix = Expr[Nothing](prefixTree)(TypeTag.Nothing)
@@ -403,8 +403,8 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
val wrappedArgs = mapWithIndex(args)((arg, j) => {
val fingerprint = implParams(min(j, implParams.length - 1))
fingerprint match {
- case LiftedTyped => context.Expr[Nothing](arg)(TypeTag.Nothing) // TODO: SI-5752
- case LiftedUntyped => arg
+ case LiftedTyped => context.Expr[Nothing](arg.duplicate)(TypeTag.Nothing) // TODO: SI-5752
+ case LiftedUntyped => arg.duplicate
case _ => abort(s"unexpected fingerprint $fingerprint in $binding with paramss being $paramss " +
s"corresponding to arg $arg in $argss")
}