Skip to content

Commit 757eb95

Browse files
committed
Fix #8871: Detect explicit splices of quoted.Type[?]
1 parent 3df9139 commit 757eb95

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
177177
case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) =>
178178
tryHeal(tp.symbol, tp, pos)
179179
case prefix: TermRef if tp.symbol.isSplice =>
180+
prefix.symbol.info.argInfos match
181+
case (tb: TypeBounds) :: _ =>
182+
ctx.error(em"Cannot splice $tp with wildcard type", pos)
183+
case _ =>
180184
// Heal explice type splice in the code
181185
if level > 0 then getQuoteTypeTags.getTagRef(prefix) else tp
182186
case prefix: TermRef if !prefix.symbol.isStatic && level > levelOf(prefix.symbol) =>

tests/pos/i6997.scala renamed to tests/neg/i6997.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import scala.quoted._
33
class Foo {
44
def mcrImpl(body: Expr[Any])(using t: Type[_ <: Any])(using ctx: QuoteContext): Expr[Any] = '{
5-
val tmp = ???.asInstanceOf[$t]
5+
val tmp = ???.asInstanceOf[$t] // error // error
66
tmp
77
}
88
}

tests/neg/i8871.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted._
2+
object Macro {
3+
def impl[A : Type](using qctx: QuoteContext): Unit = {
4+
import qctx.tasty._
5+
val tpe = typeOf[A].seal.asInstanceOf[quoted.Type[_ <: AnyRef]]
6+
'{ (a: ${tpe}) => ???} // error
7+
}
8+
}

tests/neg/i8871b.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted._
2+
object Macro {
3+
def impl[A : Type](using qctx: QuoteContext): Unit = {
4+
import qctx.tasty._
5+
val tpe/*: quoted.Type[? <: AnyKind]*/ = typeOf[A].seal
6+
'{ f[$tpe] } // error
7+
}
8+
def f[T <: AnyKind]: Unit = ()
9+
}

0 commit comments

Comments
 (0)