Skip to content

Fix #8871: Detect explicit splices of quoted.Type[?] #8872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
case prefix: ThisType if !tp.symbol.isStatic && level > levelOf(prefix.cls) =>
tryHeal(tp.symbol, tp, pos)
case prefix: TermRef if tp.symbol.isSplice =>
prefix.symbol.info.argInfos match
case (tb: TypeBounds) :: _ =>
ctx.error(em"Cannot splice $tp because it is a wildcard type", pos)
case _ =>
// Heal explicit type splice in the code
if level > 0 then getQuoteTypeTags.getTagRef(prefix) else tp
case prefix: TermRef if !prefix.symbol.isStatic && level > levelOf(prefix.symbol) =>
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/i6997.scala → tests/neg/i6997.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import scala.quoted._
class Foo {
def mcrImpl(body: Expr[Any])(using t: Type[_ <: Any])(using ctx: QuoteContext): Expr[Any] = '{
val tmp = ???.asInstanceOf[$t]
val tmp = ???.asInstanceOf[$t] // error // error
tmp
}
}
8 changes: 8 additions & 0 deletions tests/neg/i8871.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted._
object Macro {
def impl[A : Type](using qctx: QuoteContext): Unit = {
import qctx.tasty._
val tpe = typeOf[A].seal.asInstanceOf[quoted.Type[_ <: AnyRef]]
'{ (a: ${tpe}) => ???} // error
}
}
9 changes: 9 additions & 0 deletions tests/neg/i8871b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import scala.quoted._
object Macro {
def impl[A : Type](using qctx: QuoteContext): Unit = {
import qctx.tasty._
val tpe/*: quoted.Type[? <: AnyKind]*/ = typeOf[A].seal
'{ f[$tpe] } // error
}
def f[T <: AnyKind]: Unit = ()
}
5 changes: 2 additions & 3 deletions tests/pos-macros/tasty-constant-type/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ object Macro {
val ConstantType(Constant(v1: Int)) = a.unseal.tpe
val ConstantType(Constant(v2: Int)) = b.unseal.tpe

val t = Literal(Constant((v1 + v2): Int)).tpe.seal

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