Skip to content

Commit 16572cf

Browse files
committed
Allow type bounds in TypeTree.Applied for wildcard types
1 parent dc7edc2 commit 16572cf

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
@@ -92,7 +92,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
9292
this += " "
9393
printTypeTree(tpt)
9494
this += "["
95-
printTypeTrees(targs, ", ")
95+
printTypeOrBoundsTrees(targs, ", ")
9696
this += "]"
9797
if (args.nonEmpty) {
9898
this += "("
@@ -259,7 +259,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
259259
case Term.TypeApply(fn, args) =>
260260
printTree(fn)
261261
this += "["
262-
printTypeTrees(args, ", ")
262+
printTypeOrBoundsTrees(args, ", ")
263263
this += "]"
264264

265265
case Term.Super(qual, tptOpt) =>
@@ -429,12 +429,12 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
429429
this
430430
}
431431

432-
def printTypeTrees(typesTrees: List[TypeTree], sep: String): Buffer = {
433-
def printSeparated(list: List[TypeTree]): Unit = list match {
432+
def printTypeOrBoundsTrees(typesTrees: List[TypeOrBoundsTree], sep: String): Buffer = {
433+
def printSeparated(list: List[TypeOrBoundsTree]): Unit = list match {
434434
case Nil =>
435-
case x :: Nil => printTypeTree(x)
435+
case x :: Nil => printTypeOrBoundsTree(x)
436436
case x :: xs =>
437-
printTypeTree(x)
437+
printTypeOrBoundsTree(x)
438438
this += sep
439439
printSeparated(xs)
440440
}
@@ -629,7 +629,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
629629

630630
def printTypeOrBoundsTree(tpt: TypeOrBoundsTree): Buffer = tpt match {
631631
case TypeBoundsTree(lo, hi) =>
632-
this += " >: "
632+
this += "_ >: "
633633
printTypeTree(lo)
634634
this += " <: "
635635
printTypeTree(hi)
@@ -676,7 +676,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
676676
case TypeTree.Applied(tpt, args) =>
677677
printTypeTree(tpt)
678678
this += "["
679-
printTypeTrees(args, ", ")
679+
printTypeOrBoundsTrees(args, ", ")
680680
this += "]"
681681

682682
case TypeTree.Annotated(tpt, annots) =>

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)