Skip to content

Commit c4b52a0

Browse files
committed
Move synthetic type bounds to TypeBoundsTree
1 parent 969842a commit c4b52a0

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ trait CoreImpl extends scala.tasty.reflect.Core {
3737

3838
type TypeOrBoundsTree = tpd.Tree
3939
type TypeTree = tpd.Tree
40-
type TypeBoundsTree = tpd.Tree
40+
type TypeBoundsTree = tpd.TypeBoundsTree
41+
type WildcardType = tpd.TypeTree
4142

4243
type TypeOrBounds = Types.Type
4344
type NoPrefix = Types.NoPrefix.type

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

Lines changed: 11 additions & 5 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

162169
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/TypeOrBoundsTreeOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ trait TypeOrBoundsTreeOps extends Core {
9797

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

103103
val Block: BlockExtractor

0 commit comments

Comments
 (0)