Skip to content

Commit feeec24

Browse files
committed
Allow type bounds in TypeTree.Applied for wildcard types
1 parent 5416002 commit feeec24

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ object TastyImpl extends scala.tasty.Tasty {
572572
}
573573

574574
object Applied extends AppliedExtractor {
575-
def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeTree])] = x match {
575+
def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])] = x match {
576576
case x: tpd.AppliedTypeTree @unchecked => Some(x.tpt, x.args)
577577
case _ => None
578578
}

library/src/scala/tasty/Tasty.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ abstract class Tasty { tasty =>
417417

418418
val Applied: AppliedExtractor
419419
abstract class AppliedExtractor {
420-
def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeTree])]
420+
def unapply(x: TypeTree)(implicit ctx: Context): Option[(TypeTree, List[TypeOrBoundsTree])]
421421
}
422422

423423
val Annotated: AnnotatedExtractor

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ class ShowExtractors[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
253253

254254
private implicit class TypeTreeOps(buff: Buffer) {
255255
def +=(x: TypeOrBoundsTree): Buffer = { visitTypeTree(x); buff }
256-
def +=(x: Option[TypeTree]): Buffer = { visitOption(x, visitTypeTree); buff }
257-
def ++=(x: List[TypeTree]): Buffer = { visitList(x, visitTypeTree); buff }
256+
def +=(x: Option[TypeOrBoundsTree]): Buffer = { visitOption(x, visitTypeTree); buff }
257+
def ++=(x: List[TypeOrBoundsTree]): Buffer = { visitList(x, visitTypeTree); buff }
258258
}
259259

260260
private implicit class TypeOps(buff: Buffer) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
9494
this += " "
9595
printTypeTree(tpt)
9696
this += "["
97-
printTypeTrees(targs, ", ")
97+
printTypeOrBoundsTrees(targs, ", ")
9898
this += "]"
9999
if (args.nonEmpty) {
100100
this += "("
@@ -274,7 +274,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
274274
case Term.TypeApply(fn, args) =>
275275
printTree(fn)
276276
this += "["
277-
printTypeTrees(args, ", ")
277+
printTypeOrBoundsTrees(args, ", ")
278278
this += "]"
279279

280280
case Term.Super(qual, tptOpt) =>
@@ -454,12 +454,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
454454
this
455455
}
456456

457-
def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = {
458-
def printSeparated(list: List[TypeTree]): Unit = list match {
457+
def printTypeOrBoundsTrees(typesTrees: List[TypeOrBoundsTree], sep: String): Buffer = {
458+
def printSeparated(list: List[TypeOrBoundsTree]): Unit = list match {
459459
case Nil =>
460-
case x :: Nil => printTypeTree(x)
460+
case x :: Nil => printTypeOrBoundsTree(x)
461461
case x :: xs =>
462-
printTypeTree(x)
462+
printTypeOrBoundsTree(x)
463463
this += sep
464464
printSeparated(xs)
465465
}
@@ -667,7 +667,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
667667

668668
def printTypeOrBoundsTree(tpt: TypeOrBoundsTree): Buffer = tpt match {
669669
case TypeBoundsTree(lo, hi) =>
670-
this += " >: "
670+
this += "_ >: "
671671
printTypeTree(lo)
672672
this += " <: "
673673
printTypeTree(hi)
@@ -726,7 +726,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
726726
case TypeTree.Applied(tpt, args) =>
727727
printTypeTree(tpt)
728728
this += "["
729-
printTypeTrees(args, ", ")
729+
printTypeOrBoundsTrees(args, ", ")
730730
this += "]"
731731

732732
case TypeTree.Annotated(tpt, annot) =>

tests/pos/t0905.decompiled

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** Decompiled from out/posTestFromTasty/pos/t0905/Test.class */
2+
object Test {
3+
class A[T]() extends java.lang.Object
4+
def f(implicit p: Test.A[_ >: scala.Nothing <: scala.Any]): scala.Null = null
5+
implicit val x: Test.A[_ >: scala.Nothing <: scala.Any] = null
6+
scala.Predef.println(Test.f(Test.x))
7+
}

0 commit comments

Comments
 (0)