Skip to content

Commit 252a789

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

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
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/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)