Skip to content

Commit b275c38

Browse files
committed
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.
1 parent b345b42 commit b275c38

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/compiler/scala/tools/nsc/typechecker/Macros.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
345345
new {
346346
val universe: self.global.type = self.global
347347
val callsiteTyper: universe.analyzer.Typer = typer.asInstanceOf[global.analyzer.Typer]
348-
val expandee = universe.analyzer.macroExpanderAttachment(expandeeTree).original orElse expandeeTree
348+
val expandee = universe.analyzer.macroExpanderAttachment(expandeeTree).original orElse duplicateAndKeepPositions(expandeeTree)
349349
val macroRole = universe.analyzer.macroExpanderAttachment(expandeeTree).role
350350
} with UnaffiliatedMacroContext {
351351
val prefix = Expr[Nothing](prefixTree)(TypeTag.Nothing)
@@ -403,8 +403,8 @@ trait Macros extends FastTrack with MacroRuntimes with Traces with Helpers {
403403
val wrappedArgs = mapWithIndex(args)((arg, j) => {
404404
val fingerprint = implParams(min(j, implParams.length - 1))
405405
fingerprint match {
406-
case LiftedTyped => context.Expr[Nothing](arg)(TypeTag.Nothing) // TODO: SI-5752
407-
case LiftedUntyped => arg
406+
case LiftedTyped => context.Expr[Nothing](arg.duplicate)(TypeTag.Nothing) // TODO: SI-5752
407+
case LiftedUntyped => arg.duplicate
408408
case _ => abort(s"unexpected fingerprint $fingerprint in $binding with paramss being $paramss " +
409409
s"corresponding to arg $arg in $argss")
410410
}

0 commit comments

Comments
 (0)