Skip to content

Commit 93ef012

Browse files
Merge pull request #8872 from dotty-staging/fix-#8871
Fix #8871: Detect explicit splices of quoted.Type[?]
2 parents d9e6079 + 09152eb commit 93ef012

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
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 because it is a wildcard type", pos)
183+
case _ =>
180184
// Heal explicit 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+
}

tests/pos-macros/tasty-constant-type/Macro_1.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ object Macro {
1212
val ConstantType(Constant(v1: Int)) = a.unseal.tpe
1313
val ConstantType(Constant(v2: Int)) = b.unseal.tpe
1414

15-
val t = Literal(Constant((v1 + v2): Int)).tpe.seal
16-
17-
'{ null: AddInt[$a, $b] { type Out = $t } }
15+
Literal(Constant((v1 + v2): Int)).tpe.seal match
16+
case '[$t] => '{ null: AddInt[$a, $b] { type Out = $t } }
1817
}
1918
}

0 commit comments

Comments
 (0)