Skip to content

Commit 02f88fe

Browse files
committed
Fix scala#3847: Splice type splices in TypeTrees
1 parent 4e4cddb commit 02f88fe

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ class ReifyQuotes extends MacroTransform {
320320
quotation(quotedTree, tree)
321321
case Select(body, _) if tree.symbol.isSplice =>
322322
splice(body, tree)
323+
case tree: TypeTree if tree.tpe.typeSymbol.isSplice =>
324+
// FIXME handle nested spliced type like TypeTree(List[t.unary_~])
325+
val splicedType = tree.tpe.asInstanceOf[TypeRef].prefix.termSymbol
326+
splice(ref(splicedType), tree)
323327
case Block(stats, _) =>
324328
val last = enteredSyms
325329
stats.foreach(markDef)

tests/run-with-compiler/i3847-b.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
dotty.runtime.Arrays.newGenericArray[Int](3)(reflect.ClassTag.Int)
3+
}

tests/run-with-compiler/i3847-b.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import dotty.tools.dotc.quoted.Runners._
2+
import scala.quoted._
3+
import scala.reflect.ClassTag
4+
5+
object Arrays {
6+
implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T], ct: Expr[ClassTag[T]]): Liftable[Array[List[T]]] = (arr: Array[List[T]]) => '{
7+
new Array[List[~t]](~(arr.length: Expr[Int]))
8+
// TODO add elements
9+
}
10+
}
11+
12+
object Test {
13+
def main(args: Array[String]): Unit = {
14+
import Arrays._
15+
implicit val ct: Expr[ClassTag[Int]] = '(ClassTag.Int)
16+
val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3))
17+
println(arr.show)
18+
}
19+
}

tests/run-with-compiler/i3847.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
dotty.runtime.Arrays.newGenericArray[Int](3)(reflect.ClassTag.Int)
3+
}

tests/run-with-compiler/i3847.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import dotty.tools.dotc.quoted.Runners._
2+
import scala.quoted._
3+
import scala.reflect.ClassTag
4+
5+
object Arrays {
6+
implicit def ArrayIsLiftable[T: Liftable](implicit t: Type[T], ct: Expr[ClassTag[T]]): Liftable[Array[T]] = (arr: Array[T]) => '{
7+
new Array[~t](~(arr.length: Expr[Int]))(~ct)
8+
// TODO add elements
9+
}
10+
}
11+
12+
object Test {
13+
def main(args: Array[String]): Unit = {
14+
import Arrays._
15+
implicit val ct: Expr[ClassTag[Int]] = '(ClassTag.Int)
16+
val arr: Expr[Array[Int]] = Array[Int](1, 2, 3)
17+
println(arr.show)
18+
}
19+
}

0 commit comments

Comments
 (0)