diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index 4ab55c07ffef..aa570517b09c 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -1070,6 +1070,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def Tree_Bind_pattern(self: Bind)(using ctx: Context): Tree = self.body + def Tree_Bind_module_apply(sym: Symbol, body: Tree)(using ctx: Context): Bind = + tpd.Bind(sym, body) + def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind = withDefaultPos(tpd.cpy.Bind(original)(name.toTermName, pattern)) @@ -1790,6 +1793,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol)(using ctx: Context): Symbol = ctx.newSymbol(parent, name.toTermName, flags, tpe, privateWithin) + def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol = + ctx.newSymbol(parent, name.toTermName, flags | Case, tpe) + def Symbol_isTypeParam(self: Symbol)(using ctx: Context): Boolean = self.isTypeParam diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index 43b43010fa90..d52ea5c0086f 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -1494,7 +1494,8 @@ class Reflection(private[scala] val internal: CompilerInterface) { self => given (using ctx: Context) as IsInstanceOf[Bind] = internal.isInstanceOfBind object Bind { - // TODO def apply(name: String, pattern: Tree)(using ctx: Context): Bind + def apply(sym: Symbol, pattern: Tree)(using ctx: Context): Bind = + internal.Tree_Bind_module_apply(sym, pattern) def copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind = internal.Tree_Bind_module_copy(original)(name, pattern) def unapply(pattern: Bind)(using ctx: Context): Option[(String, Tree)] = @@ -2117,6 +2118,19 @@ class Reflection(private[scala] val internal: CompilerInterface) { self => def newVal(parent: Symbol, name: String, tpe: Type, flags: Flags, privateWithin: Symbol)(using ctx: Context): Symbol = internal.Symbol_newVal(parent, name, flags, tpe, privateWithin) + /** Generates a pattern bind symbol with the given parent, name and type. + * + * This symbol starts without an accompanying definition. + * It is the meta-programmer's responsibility to provide exactly one corresponding definition by passing + * this symbol to the BindDef constructor. + * + * @param flags extra flags to with which the symbol should be constructed + * @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be + * direct or indirect children of the reflection context's owner. + */ + def newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol = + internal.Symbol_newBind(parent, name, flags, tpe) + /** Definition not available */ def noSymbol(using ctx: Context): Symbol = internal.Symbol_noSymbol diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index a9de459981d5..8a64df8c2312 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -774,6 +774,8 @@ trait CompilerInterface { def Tree_Bind_pattern(self: Bind)(using ctx: Context): Tree + def Tree_Bind_module_apply(sym: Symbol, body: Tree)(using ctx: Context): Bind + def Tree_Bind_module_copy(original: Tree)(name: String, pattern: Tree)(using ctx: Context): Bind /** Tree representing an unapply pattern `Xyz(...)` */ @@ -1336,6 +1338,8 @@ trait CompilerInterface { def Symbol_newVal(parent: Symbol, name: String, flags: Flags, tpe: Type, privateWithin: Symbol)(using ctx: Context): Symbol + def Symbol_newBind(parent: Symbol, name: String, flags: Flags, tpe: Type)(using ctx: Context): Symbol + def Symbol_isTypeParam(self: Symbol)(using ctx: Context): Boolean def Symbol_isPackageDef(symbol: Symbol)(using ctx: Context): Boolean