diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-08-06 10:02:00 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-08-06 10:02:00 +1000 |
commit | 1f3319c83721401e31642c1515bd9be7c567abc1 (patch) | |
tree | c24897559afb6744233228208ccc0643fde34d6f /src | |
parent | 84d4ebc19a1e54dbe446ef35b71efa7ad3890c19 (diff) | |
download | scala-1f3319c83721401e31642c1515bd9be7c567abc1.tar.gz scala-1f3319c83721401e31642c1515bd9be7c567abc1.tar.bz2 scala-1f3319c83721401e31642c1515bd9be7c567abc1.zip |
SI-8781 Avoid double-expansion under -Ymacro-expand:discard
This mode of macro expansion is used by the presentation compiler to
leave the original macro applications ("expandees") in the type
checked trees, annotated with the types of the expansions.
However, under some circumstances involving implicits, we would
re-expand the macro. If the macro wasn't stable, this could lead
to a type mismatch.
The originally reported problem was with the shapeless
`mkSingletonOps` macro. Its expansion had the type of a freshly-named
class local to the expansion. Upon the re-expansion, a new class
was generated, which lead to errors like:
client/Client.scala:4: error: type mismatch;
found : fresh$macro$2
required: fresh$macro$1
This commit suppressed re-expansion of the expandee by use of
the existing, tree attachment driven mechanism.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Macros.scala | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 9c22688581..33d3432ae2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -576,7 +576,10 @@ trait Macros extends MacroRuntimes with Traces with Helpers { // also see http://groups.google.com/group/scala-internals/browse_thread/thread/492560d941b315cc val expanded1 = try onSuccess(duplicateAndKeepPositions(expanded)) finally popMacroContext() if (!hasMacroExpansionAttachment(expanded1)) linkExpandeeAndExpanded(expandee, expanded1) - if (settings.Ymacroexpand.value == settings.MacroExpand.Discard) expandee.setType(expanded1.tpe) + if (settings.Ymacroexpand.value == settings.MacroExpand.Discard) { + suppressMacroExpansion(expandee) + expandee.setType(expanded1.tpe) + } else expanded1 case Fallback(fallback) => onFallback(fallback) case Delayed(delayed) => onDelayed(delayed) |