@@ -210,8 +210,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
210
210
def TypeDef (sym : TypeSymbol )(implicit ctx : Context ): TypeDef =
211
211
ta.assignType(untpd.TypeDef (Modifiers (sym), sym.name, TypeTree (sym.info)), sym)
212
212
213
- def ClassDef (cls : ClassSymbol , constr : DefDef , body : List [Tree ])(implicit ctx : Context ): TypeDef = {
214
- val parents = cls.info.parents map (TypeTree (_))
213
+ def ClassDef (cls : ClassSymbol , constr : DefDef , body : List [Tree ], superArgs : List [Tree ] = Nil )(implicit ctx : Context ): TypeDef = {
214
+ val firstParent :: otherParents = cls.info.parents
215
+ val superRef =
216
+ if (cls is Trait ) TypeTree (firstParent)
217
+ else {
218
+ def isApplicable (ctpe : Type ): Boolean = ctpe match {
219
+ case ctpe : PolyType =>
220
+ isApplicable(ctpe.instantiate(firstParent.argTypes))
221
+ case ctpe : MethodType =>
222
+ (superArgs corresponds ctpe.paramTypes)(_.tpe <:< _)
223
+ case _ =>
224
+ false
225
+ }
226
+ val constr = firstParent.decl(nme.CONSTRUCTOR ).suchThat(constr => isApplicable(constr.info))
227
+ New (firstParent, constr.symbol.asTerm, superArgs)
228
+ }
229
+ val parents = superRef :: otherParents.map(TypeTree (_))
230
+
215
231
val selfType =
216
232
if (cls.classInfo.selfInfo ne NoType ) ValDef (ctx.newSelfSym(cls))
217
233
else EmptyValDef
@@ -260,10 +276,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
260
276
261
277
// ------ Creating typed equivalents of trees that exist only in untyped form -------
262
278
263
- /** new C(args) */
264
- def New (tp : Type , args : List [Tree ])(implicit ctx : Context ): Apply = {
279
+ /** new C(args), calling the primary constructor of C */
280
+ def New (tp : Type , args : List [Tree ])(implicit ctx : Context ): Apply =
281
+ New (tp, tp.typeSymbol.primaryConstructor.asTerm, args)
282
+
283
+ /** new C(args), calling given constructor `constr` of C */
284
+ def New (tp : Type , constr : TermSymbol , args : List [Tree ])(implicit ctx : Context ): Apply = {
265
285
val targs = tp.argTypes
266
- val constr = tp.typeSymbol.primaryConstructor.asTerm
267
286
Apply (
268
287
Select (
269
288
New (tp withoutArgs targs),
0 commit comments