Skip to content

Commit 363dd03

Browse files
Merge pull request #8975 from dotty-staging/fix-#8114
Fix #8114: Add bind symbol and tree constructors
2 parents e85958e + 2404589 commit 363dd03

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
@@ -1507,7 +1507,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
15071507
given (using ctx: Context) as IsInstanceOf[Bind] = internal.isInstanceOfBind
15081508

15091509
object Bind {
1510-
// TODO def apply(name: String, pattern: Tree)(using ctx: Context): Bind
1510+
def apply(sym: Symbol, pattern: Tree)(using ctx: Context): Bind =
1511+
internal.Tree_Bind_module_apply(sym, pattern)
15111512
def copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind =
15121513
internal.Tree_Bind_module_copy(original)(name, pattern)
15131514
def unapply(pattern: Bind)(using ctx: Context): Option[(String, Tree)] =
@@ -2130,6 +2131,19 @@ class Reflection(private[scala] val internal: CompilerInterface) { self =>
21302131
def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol)(using ctx: Context): Symbol =
21312132
internal.Symbol_newVal(parent, name, flags, tpe, privateWithin)
21322133

2134+
/** Generates a pattern bind symbol with the given parent, name and type.
2135+
*
2136+
* This symbol starts without an accompanying definition.
2137+
* It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing
2138+
* this symbol to the BindDef constructor.
2139+
*
2140+
* @param flags extra flags to with which the symbol should be constructed
2141+
* @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be
2142+
* direct or indirect children of the reflection context's owner.
2143+
*/
2144+
def newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol =
2145+
internal.Symbol_newBind(parent, name, flags, tpe)
2146+
21332147
/** Definition not available */
21342148
def noSymbol(using ctx: Context): Symbol =
21352149
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)