Skip to content

Commit

Permalink
Merge pull request scala#7005 from dotty-staging/fix-#6997
Browse files Browse the repository at this point in the history
Fix scala#6997: Adapt quote type direct aliase to type splice
  • Loading branch information
odersky authored Aug 23, 2019
2 parents c9d2f34 + 29a551b commit b481635
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
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
}
}

0 comments on commit b481635

Please sign in to comment.