Skip to content

Commit 906796e

Browse files
committed
Move synthetic type bounds to TypeBoundsTree
1 parent 0c6356c commit 906796e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ 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
8383

8484
type TypeOrBounds = Types.Type
8585
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
@@ -124,7 +124,7 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
124124

125125
object Bind extends BindExtractor {
126126
def unapply(x: TypeTree)(implicit ctx: Context): Option[(String, TypeBoundsTree)] = x match {
127-
case x: tpd.Bind if x.name.isTypeName => Some((x.name.toString, x.body))
127+
case x: tpd.Bind if x.name.isTypeName => Some((x.name.toString, x.body.asInstanceOf[tpd.TypeBoundsTree]))
128128
case _ => None
129129
}
130130
}
@@ -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
}

0 commit comments

Comments
 (0)