diff --git a/compiler/src/dotty/tools/dotc/transform/Splicing.scala b/compiler/src/dotty/tools/dotc/transform/Splicing.scala index ff5dc5042eaf..51cb716e47ca 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicing.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicing.scala @@ -209,7 +209,7 @@ class Splicing extends MacroTransform: // Dealias references to captured types TypeTree(tree.tpe.dealias) else super.transform(tree) - case tree: TypeTree => + case _: TypeTree | _: SingletonTypeTree => if containsCapturedType(tree.tpe) && level >= 1 then getTagRefFor(tree) else tree case tree @ Assign(lhs: RefTree, rhs) => @@ -314,10 +314,7 @@ class Splicing extends MacroTransform: ) private def capturedType(tree: Tree)(using Context): Symbol = - val tpe = tree.tpe.widenTermRefExpr - val bindingSym = refBindingMap - .getOrElseUpdate(tree.symbol, (TypeTree(tree.tpe), newQuotedTypeClassBinding(tpe)))._2 - bindingSym + refBindingMap.getOrElseUpdate(tree.symbol, (TypeTree(tree.tpe), newQuotedTypeClassBinding(tree.tpe)))._2 private def capturedPartTypes(quote: Quote)(using Context): Tree = val (tags, body1) = inContextWithQuoteTypeTags { diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index d2e70ff1aff2..f84f628fc981 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -727,7 +727,7 @@ object TreeChecker { // Check that we only add the captured type `T` instead of a more complex type like `List[T]`. // If we have `F[T]` with captured `F` and `T`, we should list `F` and `T` separately in the args. for arg <- args do - assert(arg.isTerm || arg.tpe.isInstanceOf[TypeRef], "Expected TypeRef in Hole type args but got: " + arg.tpe) + assert(arg.isTerm || arg.tpe.isInstanceOf[TypeRef | TermRef | ThisType], "Unexpected type arg in Hole: " + arg.tpe) // Check result type of the hole if isTerm then assert(tree1.typeOpt <:< pt) @@ -743,7 +743,7 @@ object TreeChecker { defn.AnyType case tpe => tpe defn.QuotedExprClass.typeRef.appliedTo(tpe) - else defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt.widenTermRefExpr) + else defn.QuotedTypeClass.typeRef.appliedTo(arg.typeOpt) } val expectedResultType = if isTerm then defn.QuotedExprClass.typeRef.appliedTo(tree1.typeOpt) diff --git a/tests/pos-macros/i17103c/Macro_1.scala b/tests/pos-macros/i17103c/Macro_1.scala new file mode 100644 index 000000000000..cb8cf43d44a8 --- /dev/null +++ b/tests/pos-macros/i17103c/Macro_1.scala @@ -0,0 +1,16 @@ +import scala.quoted.* + +inline def test = ${ testExpr } + +def testExpr(using Quotes): Expr[Unit] = + '{ + trait C + val c: C = ??? + ${ + val expr = '{ + val cRef: c.type = ??? + () + } + expr + } + } diff --git a/tests/pos-macros/i17103c/Test_2.scala b/tests/pos-macros/i17103c/Test_2.scala new file mode 100644 index 000000000000..ce2b73e5adf2 --- /dev/null +++ b/tests/pos-macros/i17103c/Test_2.scala @@ -0,0 +1 @@ +def Test = test