Skip to content

Commit d7e06ef

Browse files
Merge pull request #5475 from dotty-staging/add-missing-tasty-tree-fold-cases
Add missing case for SyntheticBounds
2 parents 189e78e + 114a5ba commit d7e06ef

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ trait CoreImpl extends scala.tasty.reflect.Core {
7979
type LambdaTypeTree = tpd.LambdaTypeTree
8080
type Bind = tpd.Bind
8181
}
82-
type TypeBoundsTree = tpd.Tree
82+
type TypeBoundsTree = tpd.TypeBoundsTree
83+
type WildcardType = tpd.TypeTree
8384

8485
type TypeOrBounds = Types.Type
8586
type NoPrefix = Types.NoPrefix.type

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
123123
}
124124

125125
object Bind extends BindExtractor {
126-
def unapply(x: TypeTree)(implicit ctx: Context): Option[(String, TypeBoundsTree)] = x match {
126+
def unapply(x: TypeTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)] = x match {
127127
case x: tpd.Bind if x.name.isTypeName => Some((x.name.toString, x.body))
128128
case _ => None
129129
}
@@ -141,27 +141,33 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
141141

142142
def TypeBoundsTreeDeco(bounds: TypeBoundsTree): TypeBoundsTreeAPI = new TypeBoundsTreeAPI {
143143
def tpe(implicit ctx: Context): TypeBounds = bounds.tpe.asInstanceOf[Types.TypeBounds]
144-
def low(implicit ctx: Context): TypeTree = bounds.asInstanceOf[tpd.TypeBoundsTree].lo
145-
def hi(implicit ctx: Context): TypeTree = bounds.asInstanceOf[tpd.TypeBoundsTree].hi
144+
def low(implicit ctx: Context): TypeTree = bounds.lo
145+
def hi(implicit ctx: Context): TypeTree = bounds.hi
146146
}
147147

148148
object IsTypeBoundsTree extends IsTypeBoundsTreeExtractor {
149149
def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[TypeBoundsTree] = x match {
150150
case x: tpd.TypeBoundsTree => Some(x)
151+
case x @ Trees.TypeTree() =>
152+
// TODO only enums generate this kind of type bounds. Is this possible without enums? If not generate tpd.TypeBoundsTree for enums instead
153+
x.tpe match {
154+
case tpe: Types.TypeBounds =>
155+
Some(tpd.TypeBoundsTree(tpd.TypeTree(tpe.lo).withPos(x.pos), tpd.TypeTree(tpe.hi).withPos(x.pos)))
156+
case _ => None
157+
}
151158
case _ => None
152159
}
153160
}
154161

155162
object TypeBoundsTree extends TypeBoundsTreeExtractor {
156163
def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)] = x match {
157-
case x: tpd.TypeBoundsTree => Some(x.lo, x.hi)
164+
case IsTypeBoundsTree(x) => Some((x.lo, x.hi))
158165
case _ => None
159166
}
160167
}
161168

162-
object SyntheticBounds extends SyntheticBoundsExtractor {
169+
object WildcardTypeTree extends WildcardTypeTreeExtractor {
163170
def unapply(x: TypeOrBoundsTree)(implicit ctx: Context): Boolean = x match {
164-
case x @ Trees.TypeTree() => x.tpe.isInstanceOf[Types.TypeBounds]
165171
case Trees.Ident(nme.WILDCARD) => x.tpe.isInstanceOf[Types.TypeBounds]
166172
case _ => false
167173
}

library/src/scala/tasty/reflect/Core.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ package scala.tasty.reflect
5252
* | +- Bind
5353
* |
5454
* +- TypeBoundsTree
55-
* +- SyntheticBounds
55+
* +- WildcardTypeTree
5656
*
5757
* +- CaseDef
5858
* +- TypeCaseDef
@@ -311,6 +311,12 @@ trait Core {
311311
/** Type tree representing a type bound written in the source */
312312
type TypeBoundsTree <: TypeOrBoundsTree
313313

314+
/** Type tree representing wildcard type bounds written in the source.
315+
* The wildcard type `_` (for example in in `List[_]`) will be a type tree that
316+
* represents a type but has `TypeBound`a inside.
317+
*/
318+
type WildcardType <: TypeOrBoundsTree
319+
314320
/** Type or bounds */
315321
type TypeOrBounds <: AnyRef
316322

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ trait Printers
190190
this += "TypeTree.Block(" ++= aliases += ", " += tpt += ")"
191191
case TypeBoundsTree(lo, hi) =>
192192
this += "TypeBoundsTree(" += lo += ", " += hi += ")"
193-
case SyntheticBounds() =>
194-
this += s"SyntheticBounds()"
193+
case WildcardTypeTree() =>
194+
this += s"WildcardTypeTree()"
195195
case TypeTree.MatchType(bound, selector, cases) =>
196196
this += "TypeTree.MatchType(" += bound += ", " += selector += ", " ++= cases += ")"
197197
}
@@ -996,7 +996,7 @@ trait Printers
996996
this += arg.name
997997
arg.rhs match {
998998
case IsTypeBoundsTree(rhs) => printBoundsTree(rhs)
999-
case rhs @ SyntheticBounds() =>
999+
case rhs @ WildcardTypeTree() =>
10001000
printTypeOrBound(rhs.tpe)
10011001
case rhs @ TypeTree.TypeLambdaTree(tparams, body) =>
10021002
def printParam(t: TypeOrBoundsTree): Unit = t match {
@@ -1184,7 +1184,7 @@ trait Printers
11841184
printTypeTree(lo)
11851185
this += " <: "
11861186
printTypeTree(hi)
1187-
case tpt @ SyntheticBounds() =>
1187+
case tpt @ WildcardTypeTree() =>
11881188
printTypeOrBound(tpt.tpe)
11891189
case IsTypeTree(tpt) =>
11901190
printTypeTree(tpt)

library/src/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ trait TreeUtils
104104
case TypeTree.Block(typedefs, tpt) => foldTypeTree(foldTrees(x, typedefs), tpt)
105105
case TypeTree.MatchType(boundopt, selector, cases) =>
106106
foldTypeCaseDefs(foldTypeTree(boundopt.fold(x)(foldTypeTree(x, _)), selector), cases)
107-
case SyntheticBounds() => x
107+
case WildcardTypeTree() => x
108108
case TypeBoundsTree(lo, hi) => foldTypeTree(foldTypeTree(x, lo), hi)
109109
}
110110

library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ trait TypeOrBoundsTreeOps extends Core {
9898

9999
val Bind: BindExtractor
100100
abstract class BindExtractor{
101-
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(String, TypeBoundsTree)]
101+
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(String, TypeOrBoundsTree)]
102102
}
103103

104104
val Block: BlockExtractor
@@ -126,10 +126,10 @@ trait TypeOrBoundsTreeOps extends Core {
126126
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Option[(TypeTree, TypeTree)]
127127
}
128128

129-
/** TypeBoundsTree containing an inferred type bounds */
130-
val SyntheticBounds: SyntheticBoundsExtractor
131-
abstract class SyntheticBoundsExtractor {
132-
/** Matches a TypeBoundsTree containing inferred type bounds */
129+
/** TypeBoundsTree containing wildcard type bounds */
130+
val WildcardTypeTree: WildcardTypeTreeExtractor
131+
abstract class WildcardTypeTreeExtractor {
132+
/** Matches a TypeBoundsTree containing wildcard type bounds */
133133
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean
134134
}
135135

0 commit comments

Comments
 (0)