Skip to content

Commit 59352c8

Browse files
committed
Set needsStaging when quotes or splices are created
1 parent e8bf7c3 commit 59352c8

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ object Applications {
217217
class ExtMethodApply(app: Tree)(implicit @constructorOnly src: SourceFile)
218218
extends IntegratedTypeArgs(app)
219219

220-
/** 1. If we are in an inline method but not in a nested quote, mark the inline method
220+
/** If we are in an inline method but not in a nested quote, mark the inline method
221221
* as a macro.
222-
*
223-
* 2. If selection is a quote or splice node, record that fact in the current compilation unit.
224222
*/
225223
def handleMeta(tree: Tree)(implicit ctx: Context): tree.type = {
226224
import transform.SymUtils._
@@ -229,15 +227,8 @@ object Applications {
229227
if (c.owner eq c.outer.owner) markAsMacro(c.outer)
230228
else if (c.owner.isInlineMethod) c.owner.setFlag(Macro)
231229
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)
232-
val sym = tree.symbol
233-
if (sym.isSplice) {
234-
if (StagingContext.level == 0)
235-
markAsMacro(ctx)
236-
ctx.compilationUnit.needsStaging = true
237-
} else if (sym.isQuote) {
238-
ctx.compilationUnit.needsStaging = true
239-
}
240-
230+
if (tree.symbol.isSplice && StagingContext.level == 0)
231+
markAsMacro(ctx)
241232
tree
242233
}
243234
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,10 @@ class Typer extends Namer
19361936
ctx.warning("Canceled splice directly inside a quote. '{ ${ XYZ } } is equivalent to XYZ.", tree.sourcePos)
19371937
typed(innerExpr, pt)
19381938
case quoted if quoted.isType =>
1939+
ctx.compilationUnit.needsStaging = true
19391940
typedTypeApply(untpd.TypeApply(untpd.ref(defn.InternalQuoted_typeQuoteR), quoted :: Nil), pt)(quoteContext).withSpan(tree.span)
19401941
case quoted =>
1942+
ctx.compilationUnit.needsStaging = true
19411943
if (ctx.mode.is(Mode.Pattern) && level == 0) {
19421944
val exprPt = pt.baseType(defn.QuotedExprClass)
19431945
val quotedPt = if (exprPt.exists) exprPt.argTypesHi.head else defn.AnyType
@@ -2012,6 +2014,7 @@ class Typer extends Namer
20122014
ctx.warning("Canceled quote directly inside a splice. ${ '{ XYZ } } is equivalent to XYZ.", tree.sourcePos)
20132015
typed(innerExpr, pt)
20142016
case expr =>
2017+
ctx.compilationUnit.needsStaging = true
20152018
if (ctx.mode.is(Mode.QuotedPattern) && level == 1) {
20162019
if (isFullyDefined(pt, ForceDegree.all)) {
20172020
def spliceOwner(ctx: Context): Symbol =
@@ -2031,6 +2034,7 @@ class Typer extends Namer
20312034

20322035
/** Translate ${ t: Type[T] }` into type `t.splice` while tracking the quotation level in the context */
20332036
def typedTypSplice(tree: untpd.TypSplice, pt: Type)(implicit ctx: Context): Tree = track("typedTypSplice") {
2037+
ctx.compilationUnit.needsStaging = true
20342038
checkSpliceOutsideQuote(tree)
20352039
typedSelect(untpd.Select(tree.expr, tpnme.splice), pt)(spliceContext).withSpan(tree.span)
20362040
}

tests/run-with-compiler/i6263.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import quoted._
2+
object Test {
3+
4+
def main(args: Array[String]): Unit = {
5+
fn("foo")
6+
fn((1,2))
7+
fn(O)
8+
fn(1)
9+
}
10+
11+
def fn[T : Type](v : T) = "ok"
12+
}
13+
14+
object O

0 commit comments

Comments
 (0)