Skip to content

Commit 5dcf4b9

Browse files
authored
Merge pull request #4775 from dotty-staging/fix-#4774
Fix #4774: Skip TypeVars and skip if level is equal
2 parents ff184cc + f51c3f8 commit 5dcf4b9

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,9 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
567567
case Quoted(quotedTree) =>
568568
quotation(quotedTree, tree)
569569
case tree: TypeTree if tree.tpe.typeSymbol.isSplice =>
570-
val splicedType = tree.tpe.asInstanceOf[TypeRef].prefix.termSymbol
571-
splice(ref(splicedType).select(tpnme.UNARY_~))
570+
val splicedType = tree.tpe.stripTypeVar.asInstanceOf[TypeRef].prefix.termSymbol
571+
if (levelOf.get(splicedType).contains(level)) tree
572+
else splice(ref(splicedType).select(tpnme.UNARY_~))
572573
case tree: Select if tree.symbol.isSplice =>
573574
splice(tree)
574575
case tree: RefTree if isCaptured(tree.symbol, level) =>

tests/neg/i4774b.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
import scala.quoted._
3+
4+
object Test {
5+
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{
6+
val y: ~t = ~x;
7+
~loop[~t]( // error
8+
'(y)
9+
)
10+
}
11+
}

tests/pos/i4774.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import scala.quoted._
3+
4+
object Test {
5+
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] =
6+
'{ val y: ~t = ~x; ~loop('(y)) }
7+
}

0 commit comments

Comments
 (0)