@@ -47,32 +47,39 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
4747 cls.info.nonPrivateMember(sym.name).hasAltWith(_.symbol == sym)
4848 }
4949
50- /** Does `method` need a forwarder to in class `cls`
51- * Method needs a forwarder in those cases:
50+ /** Does `method` need a forwarder in class `cls`?
51+ * Method needs a forwarder in these cases:
5252 * - there's a class defining a method with same signature
5353 * - there are multiple traits defining method with same signature
5454 */
55- def needsMixinForwarder (meth : Symbol ): Boolean = {
55+ def needsMixinForwarder (meth : Symbol ): Boolean =
5656 lazy val competingMethods = competingMethodsIterator(meth).toList
5757
58- def needsDisambiguation = competingMethods.exists(x => ! x .is(Deferred )) // multiple implementations are available
58+ def needsDisambiguation = competingMethods.exists(! _ .is(Deferred )) // multiple implementations are available
5959 def hasNonInterfaceDefinition = competingMethods.exists(! _.owner.is(Trait )) // there is a definition originating from class
6060
6161 // JUnit 4 won't recognize annotated default methods, so always generate a forwarder for them.
6262 def generateJUnitForwarder : Boolean =
63- meth.annotations.nonEmpty && JUnit4Annotations .exists(annot => meth.hasAnnotation(annot) ) &&
63+ meth.annotations.nonEmpty && JUnit4Annotations .exists(meth.hasAnnotation) &&
6464 ctx.settings.mixinForwarderChoices.isAtLeastJunit
6565
6666 // Similarly, Java serialization won't take into account a readResolve/writeReplace default method.
6767 def generateSerializationForwarder : Boolean =
6868 (meth.name == nme.readResolve || meth.name == nme.writeReplace) && meth.info.paramNamess.flatten.isEmpty
6969
70- ! meth.isConstructor &&
71- meth.is(Method , butNot = PrivateOrAccessorOrDeferred ) &&
72- (ctx.settings.mixinForwarderChoices.isTruthy || meth.owner.is(Scala2x ) || needsDisambiguation || hasNonInterfaceDefinition ||
73- generateJUnitForwarder || generateSerializationForwarder) &&
74- isInImplementingClass(meth)
75- }
70+ ! meth.isConstructor
71+ && meth.is(Method , butNot = PrivateOrAccessorOrDeferred )
72+ && (! meth.is(JavaDefined ) || ! meth.owner.is(Sealed ) || meth.owner.children.contains(cls))
73+ && (
74+ ctx.settings.mixinForwarderChoices.isTruthy
75+ || meth.owner.is(Scala2x )
76+ || needsDisambiguation
77+ || hasNonInterfaceDefinition
78+ || generateJUnitForwarder
79+ || generateSerializationForwarder
80+ )
81+ && isInImplementingClass(meth)
82+ end needsMixinForwarder
7683
7784 final val PrivateOrAccessor : FlagSet = Private | Accessor
7885 final val PrivateOrAccessorOrDeferred : FlagSet = Private | Accessor | Deferred
0 commit comments