@@ -228,6 +228,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
228
228
end ClassDefTypeTest
229
229
230
230
object ClassDef extends ClassDefModule :
231
+ def apply (cls : Symbol , parents : List [Tree ], body : List [Statement ]): ClassDef =
232
+ val untpdCtr = untpd.DefDef (nme.CONSTRUCTOR , Nil , tpd.TypeTree (dotc.core.Symbols .defn.UnitClass .typeRef), untpd.EmptyTree )
233
+ val ctr = ctx.typeAssigner.assignType(untpdCtr, cls.primaryConstructor)
234
+ tpd.ClassDefWithParents (cls.asClass, ctr, parents, body)
235
+
231
236
def copy (original : Tree )(name : String , constr : DefDef , parents : List [Tree ], selfOpt : Option [ValDef ], body : List [Statement ]): ClassDef = {
232
237
val dotc .ast.Trees .TypeDef (_, originalImpl : tpd.Template ) = original
233
238
tpd.cpy.TypeDef (original)(name.toTypeName, tpd.cpy.Template (originalImpl)(constr, parents, derived = Nil , selfOpt.getOrElse(tpd.EmptyValDef ), body))
@@ -260,6 +265,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
260
265
261
266
object DefDef extends DefDefModule :
262
267
def apply (symbol : Symbol , rhsFn : List [List [Tree ]] => Option [Term ]): DefDef =
268
+ assert(symbol.isTerm, s " expected a term symbol but received $symbol" )
263
269
withDefaultPos(tpd.DefDef (symbol.asTerm, prefss =>
264
270
xCheckMacroedOwners(xCheckMacroValidExpr(rhsFn(prefss)), symbol).getOrElse(tpd.EmptyTree )
265
271
))
@@ -1804,7 +1810,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
1804
1810
(x.prefix, x.name.toString)
1805
1811
end TermRef
1806
1812
1807
- type TypeRef = dotc.core.Types .NamedType
1813
+ type TypeRef = dotc.core.Types .TypeRef
1808
1814
1809
1815
object TypeRefTypeTest extends TypeTest [TypeRepr , TypeRef ]:
1810
1816
def unapply (x : TypeRepr ): Option [TypeRef & x.type ] = x match
@@ -2454,6 +2460,19 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2454
2460
def requiredModule (path : String ): Symbol = dotc.core.Symbols .requiredModule(path)
2455
2461
def requiredMethod (path : String ): Symbol = dotc.core.Symbols .requiredMethod(path)
2456
2462
def classSymbol (fullName : String ): Symbol = dotc.core.Symbols .requiredClass(fullName)
2463
+
2464
+ def newClass (owner : Symbol , name : String , parents : List [TypeRepr ], decls : Symbol => List [Symbol ], selfInfo : Option [TypeRepr ]): Symbol =
2465
+ val cls = dotc.core.Symbols .newNormalizedClassSymbol(
2466
+ owner,
2467
+ name.toTypeName,
2468
+ Flags .EmptyFlags ,
2469
+ parents,
2470
+ selfInfo.getOrElse(Types .NoType ),
2471
+ dotc.core.Symbols .NoSymbol )
2472
+ cls.enter(dotc.core.Symbols .newConstructor(cls, dotc.core.Flags .Synthetic , Nil , Nil ))
2473
+ for sym <- decls(cls) do cls.enter(sym)
2474
+ cls
2475
+
2457
2476
def newMethod (owner : Symbol , name : String , tpe : TypeRepr ): Symbol =
2458
2477
newMethod(owner, name, tpe, Flags .EmptyFlags , noSymbol)
2459
2478
def newMethod (owner : Symbol , name : String , tpe : TypeRepr , flags : Flags , privateWithin : Symbol ): Symbol =
@@ -2622,6 +2641,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2622
2641
def companionClass : Symbol = self.denot.companionClass
2623
2642
def companionModule : Symbol = self.denot.companionModule
2624
2643
def children : List [Symbol ] = self.denot.children
2644
+ def typeRef : TypeRef = self.denot.typeRef
2645
+ def termRef : TermRef = self.denot.termRef
2625
2646
2626
2647
def show (using printer : Printer [Symbol ]): String = printer.show(self)
2627
2648
0 commit comments