diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 9cc37d3716bd..156891cc2357 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -567,8 +567,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer { case Quoted(quotedTree) => quotation(quotedTree, tree) case tree: TypeTree if tree.tpe.typeSymbol.isSplice => - val splicedType = tree.tpe.asInstanceOf[TypeRef].prefix.termSymbol - splice(ref(splicedType).select(tpnme.UNARY_~)) + val splicedType = tree.tpe.stripTypeVar.asInstanceOf[TypeRef].prefix.termSymbol + if (levelOf.get(splicedType).contains(level)) tree + else splice(ref(splicedType).select(tpnme.UNARY_~)) case tree: Select if tree.symbol.isSplice => splice(tree) case tree: RefTree if isCaptured(tree.symbol, level) => diff --git a/tests/neg/i4774b.scala b/tests/neg/i4774b.scala new file mode 100644 index 000000000000..517aa02f9823 --- /dev/null +++ b/tests/neg/i4774b.scala @@ -0,0 +1,11 @@ + +import scala.quoted._ + +object Test { + def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ + val y: ~t = ~x; + ~loop[~t]( // error + '(y) + ) + } +} diff --git a/tests/pos/i4774.scala b/tests/pos/i4774.scala new file mode 100644 index 000000000000..1e17e5c953ab --- /dev/null +++ b/tests/pos/i4774.scala @@ -0,0 +1,7 @@ + +import scala.quoted._ + +object Test { + def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = + '{ val y: ~t = ~x; ~loop('(y)) } +}