Skip to content

Commit 5cf340d

Browse files
committed
Refine AnonClass generation
The leading class should be the superclass of the first trait (which is not always Object). We could think of a more refined condition, (i.e. taking the least common superclass of all extended traits), but I think it's not worth it, as one can always spell out the right superclass manually.
1 parent 0176104 commit 5cf340d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
260260
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = {
261261
val owner = fns.head.owner
262262
val parents1 =
263-
if (parents.head.classSymbol.is(Trait)) defn.ObjectType :: parents
263+
if (parents.head.classSymbol.is(Trait)) parents.head.parents.head :: parents
264264
else parents
265265
val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_FUN, Synthetic, parents1,
266266
coord = fns.map(_.pos).reduceLeft(_ union _))

0 commit comments

Comments
 (0)