Skip to content

Commit b600803

Browse files
committed
Add missing type bind symbol
1 parent f804ed0 commit b600803

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ object FromSymbol {
1414
assert(sym.exists)
1515
if (sym.is(Package)) packageDefFromSym(sym)
1616
else if (sym.isClass) classDef(sym.asClass)
17+
else if (sym.isType && sym.is(Case)) typeBindFromSym(sym.asType)
1718
else if (sym.isType) typeDefFromSym(sym.asType)
1819
else if (sym.is(Method)) defDefFromSym(sym.asTerm)
1920
else if (sym.is(Case)) bindFromSym(sym.asTerm)
@@ -54,4 +55,9 @@ object FromSymbol {
5455
case tree: tpd.Bind => tree
5556
case tpd.EmptyTree => tpd.Bind(sym, untpd.Ident(nme.WILDCARD).withType(sym.typeRef))
5657
}
58+
59+
def typeBindFromSym(sym: TypeSymbol)(implicit ctx: Context): tpd.Bind = sym.defTree match {
60+
case tree: tpd.Bind => tree
61+
case tpd.EmptyTree => tpd.Bind(sym, untpd.Ident(nme.WILDCARD).withType(sym.typeRef))
62+
}
5763
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,14 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
15141514
def TypeDefSymbol_isTypeParam(self: TypeDefSymbol)(implicit ctx: Context): Boolean =
15151515
self.isTypeParam
15161516

1517+
type TypeBindSymbol = core.Symbols.TypeSymbol
1518+
1519+
def matchTypeBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeBindSymbol] =
1520+
if (symbol.isType && symbol.is(core.Flags.Case)) Some(symbol.asType) else None
1521+
1522+
def TypeBindSymbol_tree(self: TypeBindSymbol)(implicit ctx: Context): TypeTree_TypeBind =
1523+
FromSymbol.typeBindFromSym(self)
1524+
15171525
type DefDefSymbol = core.Symbols.TermSymbol
15181526

15191527
def matchDefDefSymbol(symbol: Symbol)(implicit ctx: Context): Option[DefDefSymbol] =

docs/docs/reference/other-new-features/tasty-reflect.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ TASTy Reflect provides the following types:
180180
+- Symbol --+- PackageDefSymbol
181181
+- ClassDefSymbol
182182
+- TypeDefSymbol
183+
+- TypeBindSymbol
183184
+- DefDefSymbol
184185
+- ValDefSymbol
185186
+- BindSymbol

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ package scala.tasty.reflect
103103
* +- Symbol --+- PackageDefSymbol
104104
* +- ClassDefSymbol
105105
* +- TypeDefSymbol
106+
* +- TypeBindSymbol
106107
* +- DefDefSymbol
107108
* +- ValDefSymbol
108109
* +- BindSymbol
@@ -426,6 +427,9 @@ trait Core {
426427
/** Symbol of a type (parameter or member) definition. */
427428
type TypeDefSymbol = kernel.TypeDefSymbol
428429

430+
/** Symbol representing a type bind definition. */
431+
type TypeBindSymbol = kernel.TypeBindSymbol
432+
429433
/** Symbol representing a method definition. */
430434
type DefDefSymbol = kernel.DefDefSymbol
431435

library/src/scala/tasty/reflect/Kernel.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ package scala.tasty.reflect
102102
* +- Symbol --+- PackageDefSymbol
103103
* +- ClassDefSymbol
104104
* +- TypeDefSymbol
105+
* +- TypeBindSymbol
105106
* +- DefDefSymbol
106107
* +- ValDefSymbol
107108
* +- BindSymbol
@@ -1222,6 +1223,14 @@ trait Kernel {
12221223
/** TypeDef tree of this definition */
12231224
def TypeDefSymbol_tree(self: TypeDefSymbol)(implicit ctx: Context): TypeDef
12241225

1226+
/** Symbol representing a bind definition. */
1227+
type TypeBindSymbol <: Symbol
1228+
1229+
def matchTypeBindSymbol(symbol: Symbol)(implicit ctx: Context): Option[TypeBindSymbol]
1230+
1231+
/** TypeBind pattern of this definition */
1232+
def TypeBindSymbol_tree(self: TypeBindSymbol)(implicit ctx: Context): TypeTree_TypeBind
1233+
12251234
/** Symbol representing a method definition. */
12261235
type DefDefSymbol <: Symbol
12271236

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ trait SymbolOps extends Core {
171171
kernel.TypeDefSymbol_isTypeParam(self)
172172
}
173173

174+
// TypeBindSymbol
175+
176+
object IsTypeBindSymbol {
177+
def unapply(symbol: Symbol)(implicit ctx: Context): Option[TypeBindSymbol] =
178+
kernel.matchTypeBindSymbol(symbol)
179+
}
180+
181+
implicit class TypeBindSymbolAPI(self: TypeBindSymbol) {
182+
/** TypeBind pattern of this definition */
183+
def tree(implicit ctx: Context): TypeTree.TypeBind =
184+
kernel.TypeBindSymbol_tree(self)
185+
}
186+
174187
// DefSymbol
175188

176189
object IsDefDefSymbol {

0 commit comments

Comments
 (0)