Skip to content

Commit cdbee63

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 0fdb7e5 commit cdbee63

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

+13
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont
5959
def hasNonInterfaceDefinition = competingMethods.exists(!_.owner.is(Trait)) // there is a definition originating from class
6060
!meth.isConstructor &&
6161
meth.is(Method, butNot = PrivateOrAccessorOrDeferred) &&
62-
(meth.owner.is(Scala2x) || needsDisambiguation || hasNonInterfaceDefinition || needsJUnit4Fix(meth) ) &&
62+
(ctx.settings.mixinForwarderChoices.isTruthy || meth.owner.is(Scala2x) || needsDisambiguation || hasNonInterfaceDefinition || needsJUnit4Fix(meth)) &&
6363
isCurrent(meth)
6464
}
6565

6666
private def needsJUnit4Fix(meth: Symbol): Boolean = {
67-
meth.annotations.nonEmpty && JUnit4Annotations.exists(annot => meth.hasAnnotation(annot))
67+
meth.annotations.nonEmpty && JUnit4Annotations.exists(annot => meth.hasAnnotation(annot)) &&
68+
ctx.settings.mixinForwarderChoices.isAtLeastJunit
6869
}
6970

7071
final val PrivateOrAccessor: FlagSet = Private | Accessor

0 commit comments

Comments
 (0)