@@ -241,9 +241,23 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
241
241
242
242
object ClassDef extends ClassDefModule :
243
243
def apply (cls : Symbol , parents : List [Tree ], body : List [Statement ]): ClassDef =
244
- val untpdCtr = untpd.DefDef (nme.CONSTRUCTOR , Nil , tpd.TypeTree (dotc.core.Symbols .defn.UnitClass .typeRef), tpd.EmptyTree )
244
+ val paramsDefs : List [untpd.ParamClause ] =
245
+ cls.primaryConstructor.paramSymss.map { paramSym =>
246
+ paramSym.map( symm =>
247
+ ValDef (symm, None )
248
+ )
249
+ }
250
+ val paramsAccessDefs : List [untpd.ParamClause ] =
251
+ cls.primaryConstructor.paramSymss.map { paramSym =>
252
+ paramSym.map( symm =>
253
+ ValDef (cls.fieldMember(symm.name.toString()), None ) // TODO I don't like the toString here
254
+ )
255
+ }
256
+
257
+ val termSymbol : dotc.core.Symbols .TermSymbol = cls.primaryConstructor.asTerm
258
+ val untpdCtr = untpd.DefDef (nme.CONSTRUCTOR , paramsDefs, tpd.TypeTree (dotc.core.Symbols .defn.UnitClass .typeRef), tpd.EmptyTree )
245
259
val ctr = ctx.typeAssigner.assignType(untpdCtr, cls.primaryConstructor)
246
- tpd.ClassDefWithParents (cls.asClass, ctr, parents, body)
260
+ tpd.ClassDefWithParents (cls.asClass, ctr, parents, paramsAccessDefs.flatten ++ body)
247
261
248
262
def copy (original : Tree )(name : String , constr : DefDef , parents : List [Tree ], selfOpt : Option [ValDef ], body : List [Statement ]): ClassDef = {
249
263
val dotc .ast.Trees .TypeDef (_, originalImpl : tpd.Template ) = original : @ unchecked
@@ -2605,10 +2619,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2605
2619
def requiredMethod (path : String ): Symbol = dotc.core.Symbols .requiredMethod(path)
2606
2620
def classSymbol (fullName : String ): Symbol = dotc.core.Symbols .requiredClass(fullName)
2607
2621
2608
- def newClass (owner : Symbol , name : String , parents : List [TypeRepr ], decls : Symbol => List [Symbol ], selfType : Option [TypeRepr ]): Symbol =
2622
+ def newClass (parent : Symbol , name : String , parents : List [TypeRepr ], decls : Symbol => List [Symbol ], selfType : Option [TypeRepr ]): Symbol =
2609
2623
assert(parents.nonEmpty && ! parents.head.typeSymbol.is(dotc.core.Flags .Trait ), " First parent must be a class" )
2610
2624
val cls = dotc.core.Symbols .newNormalizedClassSymbol(
2611
- owner ,
2625
+ parent ,
2612
2626
name.toTypeName,
2613
2627
dotc.core.Flags .EmptyFlags ,
2614
2628
parents,
@@ -2618,6 +2632,22 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
2618
2632
for sym <- decls(cls) do cls.enter(sym)
2619
2633
cls
2620
2634
2635
+ def newClass (parent : Symbol , name : String , parents : List [TypeRepr ], decls : Symbol => List [Symbol ], selfType : Option [TypeRepr ], paramNames : List [String ], paramTypes : List [TypeRepr ], flags : Flags , privateWithin : Symbol ): Symbol =
2636
+ assert(parents.nonEmpty && ! parents.head.typeSymbol.is(dotc.core.Flags .Trait ), " First parent must be a class" )
2637
+ checkValidFlags(flags.toTermFlags, Flags .validClassFlags)
2638
+ val cls = dotc.core.Symbols .newNormalizedClassSymbol(
2639
+ parent,
2640
+ name.toTypeName,
2641
+ flags,
2642
+ parents,
2643
+ selfType.getOrElse(Types .NoType ),
2644
+ privateWithin)
2645
+ cls.enter(dotc.core.Symbols .newConstructor(cls, dotc.core.Flags .Synthetic , paramNames.map(_.toTermName), paramTypes))
2646
+ for (name, tpe) <- paramNames.zip(paramTypes) do
2647
+ cls.enter(dotc.core.Symbols .newSymbol(cls, name.toTermName, Flags .ParamAccessor , tpe, Symbol .noSymbol)) // add other flags (local, private, privatelocal) and set privateWithin
2648
+ for sym <- decls(cls) do cls.enter(sym)
2649
+ cls
2650
+
2621
2651
def newModule (owner : Symbol , name : String , modFlags : Flags , clsFlags : Flags , parents : List [TypeRepr ], decls : Symbol => List [Symbol ], privateWithin : Symbol ): Symbol =
2622
2652
assert(parents.nonEmpty && ! parents.head.typeSymbol.is(dotc.core.Flags .Trait ), " First parent must be a class" )
2623
2653
assert(! privateWithin.exists || privateWithin.isType, " privateWithin must be a type symbol or `Symbol.noSymbol`" )
@@ -3006,6 +3036,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
3006
3036
// Keep: aligned with Quotes's `newTypeAlias` doc
3007
3037
private [QuotesImpl ] def validTypeAliasFlags : Flags = Private | Protected | Override | Final | Infix | Local
3008
3038
3039
+ // Keep: aligned with Quotes's `newClass`
3040
+ private [QuotesImpl ] def validClassFlags : Flags = Private | Protected | Final // Abstract, AbsOverride Local OPen ? PrivateLocal Protected ?
3041
+
3009
3042
end Flags
3010
3043
3011
3044
given FlagsMethods : FlagsMethods with
0 commit comments