@@ -48,33 +48,40 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
48
48
cls.info.nonPrivateMember(sym.name).hasAltWith(_.symbol == sym)
49
49
}
50
50
51
- /** Does `method` need a forwarder to in class `cls`
52
- * Method needs a forwarder in those cases:
51
+ /** Does `method` need a forwarder in class `cls`?
52
+ * Method needs a forwarder in these cases:
53
53
* - there's a class defining a method with same signature
54
54
* - there are multiple traits defining method with same signature
55
55
*/
56
- def needsMixinForwarder (meth : Symbol ): Boolean = {
56
+ def needsMixinForwarder (meth : Symbol ): Boolean =
57
57
lazy val competingMethods = competingMethodsIterator(meth).toList
58
58
59
- def needsDisambiguation = competingMethods.exists(x => ! x .is(Deferred )) // multiple implementations are available
59
+ def needsDisambiguation = competingMethods.exists(! _ .is(Deferred )) // multiple implementations are available
60
60
def hasNonInterfaceDefinition = competingMethods.exists(! _.owner.is(Trait )) // there is a definition originating from class
61
61
62
62
// JUnit 4 won't recognize annotated default methods, so always generate a forwarder for them.
63
63
def generateJUnitForwarder : Boolean =
64
- meth.annotations.nonEmpty && JUnit4Annotations .exists(annot => meth.hasAnnotation(annot) ) &&
64
+ meth.annotations.nonEmpty && JUnit4Annotations .exists(meth.hasAnnotation) &&
65
65
ctx.settings.mixinForwarderChoices.isAtLeastJunit
66
66
67
67
// Similarly, Java serialization won't take into account a readResolve/writeReplace default method.
68
68
def generateSerializationForwarder : Boolean =
69
69
(meth.name == nme.readResolve || meth.name == nme.writeReplace) && meth.info.paramNamess.flatten.isEmpty
70
70
71
- ! meth.isConstructor &&
72
- meth.is(Method , butNot = PrivateOrAccessorOrDeferred ) &&
73
- (ctx.settings.mixinForwarderChoices.isTruthy || meth.owner.is(Scala2x ) || needsDisambiguation || hasNonInterfaceDefinition ||
74
- generateJUnitForwarder || generateSerializationForwarder) &&
75
- isInImplementingClass(meth) &&
76
- ! meth.name.is(InlineAccessorName )
77
- }
71
+ ! meth.isConstructor
72
+ && meth.is(Method , butNot = PrivateOrAccessorOrDeferred )
73
+ && (! meth.is(JavaDefined ) || ! meth.owner.is(Sealed ) || meth.owner.children.contains(cls))
74
+ && (
75
+ ctx.settings.mixinForwarderChoices.isTruthy
76
+ || meth.owner.is(Scala2x )
77
+ || needsDisambiguation
78
+ || hasNonInterfaceDefinition
79
+ || generateJUnitForwarder
80
+ || generateSerializationForwarder
81
+ )
82
+ && isInImplementingClass(meth)
83
+ && ! meth.name.is(InlineAccessorName )
84
+ end needsMixinForwarder
78
85
79
86
final val PrivateOrAccessor : FlagSet = Private | Accessor
80
87
final val PrivateOrAccessorOrDeferred : FlagSet = Private | Accessor | Deferred
0 commit comments