Skip to content

Commit cf2c202

Browse files
authored
Merge pull request #4780 from dotty-staging/fix-#4774
Disallow inferred splices and set the correct position
2 parents fe6ab99 + a667a4b commit cf2c202

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
568568
quotation(quotedTree, tree)
569569
case tree: TypeTree if tree.tpe.typeSymbol.isSplice =>
570570
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_~))
571+
splice(ref(splicedType).select(tpnme.UNARY_~).withPos(tree.pos))
573572
case tree: Select if tree.symbol.isSplice =>
574573
splice(tree)
575574
case tree: RefTree if isCaptured(tree.symbol, level) =>

tests/neg/i4774a.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( // error: inferred loop[~t] where T should be used
8+
'(y)
9+
)
10+
}
11+
}

tests/pos/i4774c.scala

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

tests/pos/i4774.scala renamed to tests/pos/i4774d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import scala.quoted._
33

44
object Test {
55
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] =
6-
'{ val y: ~t = ~x; ~loop('(y)) }
6+
'{ val y: T = ~x; ~loop('(y)) }
77
}

0 commit comments

Comments
 (0)