Skip to content

Commit a779493

Browse files
committed
Fix handling of top level Type.Underlying references
1 parent 14a9131 commit a779493

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class ReifyQuotes extends MacroTransform {
7777
case tree: RefTree if !Inliner.inInlineMethod =>
7878
assert(!tree.symbol.isQuote)
7979
assert(!tree.symbol.isExprSplice)
80-
assert(!tree.symbol.isTypeSplice)
8180
case _ : TypeDef =>
8281
assert(!tree.symbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot),
8382
s"${tree.symbol} should have been removed by PickledQuotes because it has a @quoteTypeTag")
@@ -210,16 +209,15 @@ class ReifyQuotes extends MacroTransform {
210209
* are in the body of an inline method.
211210
*/
212211
protected def transformSpliceType(body: Tree, splice: Select)(using Context): Tree =
213-
if (level > 1) {
212+
if level > 1 then
214213
val body1 = nested(isQuote = false).transform(body)(using spliceContext)
215214
cpy.Select(splice)(body1, splice.name)
216-
}
217-
else {
218-
assert(level == 1, "unexpected top splice outside quote")
215+
else if level == 1 then
219216
val (body1, quotes) = nested(isQuote = false).splitSplice(body)(using spliceContext)
220217
val tpe = outer.embedded.getHoleType(body, splice)
221218
makeHole(splice.isTerm, body1, quotes, tpe).withSpan(splice.span)
222-
}
219+
else
220+
splice
223221

224222
/** Transforms the contents of a nested splice
225223
* Assuming

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,8 @@ trait QuotesAndSplices {
180180
else
181181
val tree1 = typedSelect(untpd.Select(tree.expr, tpnme.Underlying), pt)(using spliceContext).withSpan(tree.span)
182182
val msg = em"Consider using canonical type reference ${tree1.tpe} instead"
183-
// if sourceVersion.isAtLeast(`3.1-migration`) then
184-
report.error(msg, tree.srcPos)
185-
// else report.warning(msg, tree.srcPos)
183+
if sourceVersion.isAtLeast(`3.1-migration`) then report.error(msg, tree.srcPos)
184+
else report.warning(msg, tree.srcPos)
186185
tree1
187186
}
188187

tests/neg-macros/i4774b.scala renamed to tests/pos-macros/i4774b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import scala.quoted._
44
object Test {
55
def loop[T](x: Expr[T])(implicit t: Type[T], qctx: QuoteContext): Expr[T] = '{
66
val y: t.Underlying = $x;
7-
${loop[t.Underlying]( // error
7+
${loop[t.Underlying](
88
'y
99
)}
1010
}

0 commit comments

Comments
 (0)