Skip to content

Commit 8b41240

Browse files
committed
Merge pull request scala#2720 from adriaanm/ticket-7487
SI-7487 Revert "Removed -Ymacro-no-expand."
2 parents 7125dc3 + be39391 commit 8b41240

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ trait ScalaSettings extends AbsScalaSettings
166166
val Yrangepos = BooleanSetting ("-Yrangepos", "Use range positions for syntax trees.")
167167
val Ymemberpos = StringSetting ("-Yshow-member-pos", "output style", "Show start and end positions of members", "") withPostSetHook (_ => Yrangepos.value = true)
168168
val Yreifycopypaste = BooleanSetting ("-Yreify-copypaste", "Dump the reified trees in copypasteable representation.")
169+
val Ymacronoexpand = BooleanSetting ("-Ymacro-no-expand", "Don't expand macros. Might be useful for scaladoc and presentation compiler, but will crash anything which uses macros and gets past typer.")
169170
val Yreplsync = BooleanSetting ("-Yrepl-sync", "Do not use asynchronous code for repl startup")
170171
val Yreploutdir = StringSetting ("-Yrepl-outdir", "path", "Write repl-generated classfiles to given output directory (use \"\" to generate a temporary dir)" , "")
171172
val YmethodInfer = BooleanSetting ("-Yinfer-argument-types", "Infer types for arguments of overriden methods.")

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ trait StdAttachments {
100100
/** Determines whether a tree should not be expanded, because someone has put SuppressMacroExpansionAttachment on it or one of its children.
101101
*/
102102
def isMacroExpansionSuppressed(tree: Tree): Boolean =
103-
if (tree.attachments.get[SuppressMacroExpansionAttachment.type].isDefined) true
104-
else tree match {
105-
// we have to account for the fact that during typechecking an expandee might become wrapped,
106-
// i.e. surrounded by an inferred implicit argument application or by an inferred type argument application.
107-
// in that case the expandee itself will no longer be suppressed and we need to look at the core
108-
case Apply(fn, _) => isMacroExpansionSuppressed(fn)
109-
case TypeApply(fn, _) => isMacroExpansionSuppressed(fn)
110-
case _ => false
111-
}
103+
( settings.Ymacronoexpand.value // SI-6812
104+
|| tree.attachments.get[SuppressMacroExpansionAttachment.type].isDefined
105+
|| (tree match {
106+
// we have to account for the fact that during typechecking an expandee might become wrapped,
107+
// i.e. surrounded by an inferred implicit argument application or by an inferred type argument application.
108+
// in that case the expandee itself will no longer be suppressed and we need to look at the core
109+
case Apply(fn, _) => isMacroExpansionSuppressed(fn)
110+
case TypeApply(fn, _) => isMacroExpansionSuppressed(fn)
111+
case _ => false
112+
})
113+
)
112114

113115
/** After being synthesized by the parser, primary constructors aren't fully baked yet.
114116
* A call to super in such constructors is just a fill-me-in-later dummy resolved later
@@ -154,4 +156,4 @@ trait StdAttachments {
154156
* because someone has put MacroImplRefAttachment on it.
155157
*/
156158
def isMacroImplRef(tree: Tree): Boolean = tree.attachments.get[MacroImplRefAttachment.type].isDefined
157-
}
159+
}

test/scaladoc/run/SI-6812.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import scala.tools.nsc.doc.model._
2+
import scala.tools.partest.ScaladocModelTest
3+
import language._
4+
5+
object Test extends ScaladocModelTest {
6+
7+
override def code = """
8+
import scala.reflect.macros.Context
9+
import language.experimental.macros
10+
11+
object Macros {
12+
def impl(c: Context) = c.literalUnit
13+
def foo = macro impl
14+
}
15+
16+
class C {
17+
def bar = Macros.foo
18+
}
19+
"""
20+
21+
def scaladocSettings = ""
22+
override def extraSettings = super.extraSettings + " -Ymacro-no-expand"
23+
def testModel(root: Package) = ()
24+
}

0 commit comments

Comments
 (0)