Skip to content

Commit 10aeb0e

Browse files
Merge pull request #4687 from dotty-staging/fix-tasty-constant-type
Add Tasty.Constant.ClassTag
2 parents 3f69a4e + 38fe18b commit 10aeb0e

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,13 @@ object TastyImpl extends scala.tasty.Tasty {
940940
}
941941
}
942942

943+
object ClassTag extends ClassTagExtractor {
944+
def unapply(x: Constant): Option[Type] = x match {
945+
case x: Constants.Constant if x.tag == Constants.ClazzTag => Some(x.typeValue)
946+
case _ => None
947+
}
948+
}
949+
943950
}
944951

945952
// ===== Signature ================================================

library/src/scala/tasty/Tasty.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@ abstract class Tasty { tasty =>
731731
def unapply(x: Constant): Option[String]
732732
}
733733

734+
val ClassTag: ClassTagExtractor
735+
abstract class ClassTagExtractor {
736+
def unapply(x: Constant): Option[Type]
737+
}
734738
}
735739

736740
// ===== Signature ================================================

library/src/scala/tasty/util/ShowExtractors.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
150150
case Constant.Float(value) => this += "Constant.Float(" += value += ")"
151151
case Constant.Double(value) => this += "Constant.Double(" += value += ")"
152152
case Constant.String(value) => this += "Constant.String(\"" += value += "\")"
153+
case Constant.ClassTag(value) => this += "Constant.ClassTag(" += value += ")"
153154
}
154155

155156
def visitType(x: TypeOrBounds): Buffer = x match {

library/src/scala/tasty/util/ShowSourceCode.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
237237

238238
case Term.Select(qual, name, sig) =>
239239
printTree(qual)
240-
if (name != "<init>")
240+
if (name != "<init>" && name != "package")
241241
this += "." += name
242242
this
243243

@@ -664,6 +664,10 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
664664
case Constant.Double(v) => this += v
665665
case Constant.Char(v) => this += '\'' += escapedChar(v) += '\''
666666
case Constant.String(v) => this += '"' += escapedString(v) += '"'
667+
case Constant.ClassTag(v) =>
668+
this += "classOf["
669+
printType(v)
670+
this += "]"
667671
}
668672

669673
def printTypeOrBoundsTree(tpt: TypeOrBoundsTree): Buffer = tpt match {

tests/pos/i566.decompiled

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Decompiled from out/posTestFromTasty/pos/i566/Test.class */
2+
class Test() {
3+
type T = scala.Predef.String
4+
type U
5+
scala.reflect.classTag[Test.this.T](scala.reflect.ClassTag.apply[Test.this.T](classOf[java.lang.String]))
6+
}

0 commit comments

Comments
 (0)