Skip to content

Commit 509c4ef

Browse files
committed
Add -Xmixin-force-forwarders
This controls when mixin forwarders are generated like the homonymous flag in scalac, for now we default to "junit" to keep our existing behavior, next commit will change it to "true" to match scalac.
1 parent 6eefc75 commit 509c4ef

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.dotc
22
package config
33

4+
import dotty.tools.dotc.core.Contexts.Context
45
import dotty.tools.io.{ Directory, PlainDirectory, AbstractFile }
56
import PathResolver.Defaults
67
import rewrites.Rewrites
@@ -76,6 +77,18 @@ class ScalaSettings extends Settings.SettingGroup {
7677
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
7778
val XverifySignatures: Setting[Boolean] = BooleanSetting("-Xverify-signatures", "Verify generic signatures in generated bytecode.")
7879

80+
val XmixinForceForwarders = ChoiceSetting(
81+
name = "-Xmixin-force-forwarders",
82+
helpArg = "mode",
83+
descr = "Generate forwarder methods in classes inhering concrete methods from traits.",
84+
choices = List("true", "junit", "false"),
85+
default = "junit")
86+
87+
object mixinForwarderChoices {
88+
def isTruthy(implicit ctx: Context) = XmixinForceForwarders.value == "true"
89+
def isAtLeastJunit(implicit ctx: Context) = isTruthy || XmixinForceForwarders.value == "junit"
90+
}
91+
7992
/** -Y "Private" settings */
8093
val YoverrideVars: Setting[Boolean] = BooleanSetting("-Yoverride-vars", "Allow vars to be overridden.")
8194
val Yhelp: Setting[Boolean] = BooleanSetting("-Y", "Print a synopsis of private options.")

compiler/src/dotty/tools/dotc/transform/MixinOps.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
6565
def hasNonInterfaceDefinition = competingMethods.exists(!_.owner.is(Trait)) // there is a definition originating from class
6666
!meth.isConstructor &&
6767
meth.is(Method, butNot = PrivateOrAccessorOrDeferred) &&
68-
(meth.owner.is(Scala2x) || needsDisambiguation || hasNonInterfaceDefinition || needsJUnit4Fix(meth) ) &&
68+
(ctx.settings.mixinForwarderChoices.isTruthy || meth.owner.is(Scala2x) || needsDisambiguation || hasNonInterfaceDefinition || needsJUnit4Fix(meth)) &&
6969
isCurrent(meth)
7070
}
7171

7272
private def needsJUnit4Fix(meth: Symbol): Boolean = {
73-
meth.annotations.nonEmpty && JUnit4Annotations.exists(annot => meth.hasAnnotation(annot))
73+
meth.annotations.nonEmpty && JUnit4Annotations.exists(annot => meth.hasAnnotation(annot)) &&
74+
ctx.settings.mixinForwarderChoices.isAtLeastJunit
7475
}
7576

7677
final val PrivateOrAccessor: FlagSet = Private | Accessor

0 commit comments

Comments
 (0)