Skip to content

Fix #6997: Adapt quote type direct aliase to type splice #7005

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
Aug 23, 2019
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 @@ -112,6 +112,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
if (tp.isTerm)
ctx.error(i"splice outside quotes", pos)
tp
case tp: TypeRef if tp.symbol == defn.QuotedTypeClass.typeParams.head =>
// Adapt direct references to the type of the type parameter T of a quoted.Type[T].
// Replace it with a properly encoded type splice. This is the normal for expected for type splices.
tp.prefix.select(tpnme.splice)
case tp: NamedType =>
checkSymLevel(tp.symbol, tp, pos) match {
case Some(tpRef) => tpRef.tpe
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i6997.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

import scala.quoted._
class Foo {
def mcrImpl(body: Expr[Any]) given (t: Type[_ <: Any]) given (ctx: QuoteContext): Expr[Any] = '{
val tmp = ???.asInstanceOf[$t]
tmp
}
}
15 changes: 15 additions & 0 deletions tests/pos/i6997b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package playground

import scala.quoted._, scala.quoted.matching._
import delegate scala.quoted._

inline def mcr(x: => Any): Any = ${mcrImpl('x)}

def mcrImpl(body: Expr[Any]) given (ctx: QuoteContext): Expr[Any] = {
val '{$x: $t} = body
'{
val tmp: $t = $x.asInstanceOf[$t]
println(tmp)
tmp
}
}