@@ -47,32 +47,39 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
47
47
cls.info.nonPrivateMember(sym.name).hasAltWith(_.symbol == sym)
48
48
}
49
49
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:
52
52
* - there's a class defining a method with same signature
53
53
* - there are multiple traits defining method with same signature
54
54
*/
55
- def needsMixinForwarder (meth : Symbol ): Boolean = {
55
+ def needsMixinForwarder (meth : Symbol ): Boolean =
56
56
lazy val competingMethods = competingMethodsIterator(meth).toList
57
57
58
- def needsDisambiguation = competingMethods.exists(x => ! x .is(Deferred )) // multiple implementations are available
58
+ def needsDisambiguation = competingMethods.exists(! _ .is(Deferred )) // multiple implementations are available
59
59
def hasNonInterfaceDefinition = competingMethods.exists(! _.owner.is(Trait )) // there is a definition originating from class
60
60
61
61
// JUnit 4 won't recognize annotated default methods, so always generate a forwarder for them.
62
62
def generateJUnitForwarder : Boolean =
63
- meth.annotations.nonEmpty && JUnit4Annotations .exists(annot => meth.hasAnnotation(annot) ) &&
63
+ meth.annotations.nonEmpty && JUnit4Annotations .exists(meth.hasAnnotation) &&
64
64
ctx.settings.mixinForwarderChoices.isAtLeastJunit
65
65
66
66
// Similarly, Java serialization won't take into account a readResolve/writeReplace default method.
67
67
def generateSerializationForwarder : Boolean =
68
68
(meth.name == nme.readResolve || meth.name == nme.writeReplace) && meth.info.paramNamess.flatten.isEmpty
69
69
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.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
76
83
77
84
final val PrivateOrAccessor : FlagSet = Private | Accessor
78
85
final val PrivateOrAccessorOrDeferred : FlagSet = Private | Accessor | Deferred
0 commit comments