Skip to content

Commit 777d666

Browse files
committed
Fix tags in quoted.Type
1 parent 2105863 commit 777d666

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import dotty.tools.dotc.core.Symbols._
1212
import dotty.tools.dotc.core.tasty.{TastyPickler, TastyPrinter, TastyString}
1313
import dotty.tools.dotc.interpreter.RawQuoted
1414

15+
import scala.reflect.ClassTag
16+
1517
object PickledQuotes {
1618
import tpd._
1719

@@ -33,6 +35,18 @@ object PickledQuotes {
3335
def quotedToTree(expr: quoted.Quoted)(implicit ctx: Context): Tree = expr match {
3436
case expr: quoted.TastyQuoted => unpickleQuote(expr)
3537
case expr: quoted.Liftable.ConstantExpr[_] => Literal(Constant(expr.value))
38+
case expr: quoted.Type.TaggedPrimitive[_] =>
39+
val tpe = expr.ct match {
40+
case ClassTag.Unit => defn.UnitType
41+
case ClassTag.Byte => defn.ByteType
42+
case ClassTag.Char => defn.CharType
43+
case ClassTag.Short => defn.ShortType
44+
case ClassTag.Int => defn.IntType
45+
case ClassTag.Long => defn.LongType
46+
case ClassTag.Float => defn.FloatType
47+
case ClassTag.Double => defn.FloatType
48+
}
49+
TypeTree(tpe)
3650
case expr: RawQuoted => expr.tree
3751
}
3852

library/src/scala/quoted/Type.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
package scala.quoted
22

3+
import scala.reflect.ClassTag
4+
35
class Type[T] extends Quoted {
46
type unary_~ = T
57
}
68

79
/** Some basic type tags, currently incomplete */
810
object Type {
9-
implicit def IntTag: Type[Int] = new Type[Int]
10-
implicit def BooleanTag: Type[Boolean] = new Type[Boolean]
11+
12+
class TaggedPrimitive[T] private[Type] (implicit val ct: ClassTag[T]) extends Type[T]
13+
14+
implicit def UnitTag: Type[Unit] = new TaggedPrimitive[Unit]
15+
implicit def BooleanTag: Type[Boolean] = new TaggedPrimitive[Boolean]
16+
implicit def ByteTag: Type[Byte] = new TaggedPrimitive[Byte]
17+
implicit def CharTag: Type[Char] = new TaggedPrimitive[Char]
18+
implicit def ShortTag: Type[Short] = new TaggedPrimitive[Short]
19+
implicit def IntTag: Type[Int] = new TaggedPrimitive[Int]
20+
implicit def LongTag: Type[Long] = new TaggedPrimitive[Long]
21+
implicit def FloatTag: Type[Float] = new TaggedPrimitive[Float]
22+
implicit def DoubleTag: Type[Double] = new TaggedPrimitive[Double]
1123
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
val z: Int = 2
3+
()
4+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import dotty.tools.dotc.quoted.Runners._
2+
import scala.quoted._
3+
object Test {
4+
def main(args: Array[String]): Unit = {
5+
def f[T](x: Expr[T])(t: Type[T]) = '{
6+
val z: t.unary_~ = ~x
7+
}
8+
println(f('(2))(Type.IntTag).show)
9+
}
10+
}

0 commit comments

Comments
 (0)