Skip to content

Commit 2404589

Browse files
committed
Fix #8114: Add bind symbol and tree constructors
1 parent f807eee commit 2404589

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
10701070

10711071
def Tree_Bind_pattern(self: Bind)(using ctx: Context): Tree = self.body
10721072

1073+
def Tree_Bind_module_apply(sym: Symbol, body: Tree)(using ctx: Context): Bind =
1074+
tpd.Bind(sym, body)
1075+
10731076
def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind =
10741077
withDefaultPos(tpd.cpy.Bind(original)(name.toTermName, pattern))
10751078

@@ -1790,6 +1793,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
17901793
def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol)(using ctx: Context): Symbol =
17911794
ctx.newSymbol(parent, name.toTermName, flags, tpe, privateWithin)
17921795

1796+
def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol =
1797+
ctx.newSymbol(parent, name.toTermName, flags | Case, tpe)
1798+
17931799
def Symbol_isTypeParam(self: Symbol)(using ctx: Context): Boolean =
17941800
self.isTypeParam
17951801

library/src/scala/tasty/Reflection.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
14941494
given (using ctx: Context) as IsInstanceOf[Bind] = internal.isInstanceOfBind
14951495

14961496
object Bind {
1497-
// TODO def apply(name: String, pattern: Tree)(using ctx: Context): Bind
1497+
def apply(sym: Symbol, pattern: Tree)(using ctx: Context): Bind =
1498+
internal.Tree_Bind_module_apply(sym, pattern)
14981499
def copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind =
14991500
internal.Tree_Bind_module_copy(original)(name, pattern)
15001501
def unapply(pattern: Bind)(using ctx: Context): Option[(String, Tree)] =
@@ -2117,6 +2118,19 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
21172118
def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol)(using ctx: Context): Symbol =
21182119
internal.Symbol_newVal(parent, name, flags, tpe, privateWithin)
21192120

2121+
/** Generates a pattern bind symbol with the given parent, name and type.
2122+
*
2123+
* This symbol starts without an accompanying definition.
2124+
* It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing
2125+
* this symbol to the BindDef constructor.
2126+
*
2127+
* @param flags extra flags to with which the symbol should be constructed
2128+
* @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be
2129+
* direct or indirect children of the reflection context's owner.
2130+
*/
2131+
def newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol =
2132+
internal.Symbol_newBind(parent, name, flags, tpe)
2133+
21202134
/** Definition not available */
21212135
def noSymbol(using ctx: Context): Symbol =
21222136
internal.Symbol_noSymbol

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ trait CompilerInterface {
774774

775775
def Tree_Bind_pattern(self: Bind)(using ctx: Context): Tree
776776

777+
def Tree_Bind_module_apply(sym: Symbol, body: Tree)(using ctx: Context): Bind
778+
777779
def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind
778780

779781
/** Tree representing an unapply pattern `Xyz(...)` */
@@ -1336,6 +1338,8 @@ trait CompilerInterface {
13361338

13371339
def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol)(using ctx: Context): Symbol
13381340

1341+
def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol
1342+
13391343
def Symbol_isTypeParam(self: Symbol)(using ctx: Context): Boolean
13401344

13411345
def Symbol_isPackageDef(symbol: Symbol)(using ctx: Context): Boolean

0 commit comments

Comments
 (0)