diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-09-01 14:46:37 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-09-02 07:14:16 +0200 |
commit | 2277d37982bffb666b5c4bdb655d44234885e0bb (patch) | |
tree | 3da8419d8ff5a6056aa4a8856aefe63486257867 | |
parent | fdfdd253bfb4e44faf4afce1da56989ce132e15c (diff) | |
download | scala-2277d37982bffb666b5c4bdb655d44234885e0bb.tar.gz scala-2277d37982bffb666b5c4bdb655d44234885e0bb.tar.bz2 scala-2277d37982bffb666b5c4bdb655d44234885e0bb.zip |
Add a -Xmixin-force-forwarders ChoiceSetting
4 files changed, 22 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index bb1d760d86..e10fa3a114 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -133,7 +133,22 @@ trait ScalaSettings extends AbsScalaSettings val XnoPatmatAnalysis = BooleanSetting ("-Xno-patmat-analysis", "Don't perform exhaustivity/unreachability analysis. Also, ignore @switch annotation.") val XfullLubs = BooleanSetting ("-Xfull-lubs", "Retains pre 2.10 behavior of less aggressive truncation of least upper bounds.") - val XgenMixinForwarders = BooleanSetting("-Xgen-mixin-forwarders", "Generate forwarder methods in classes inhering concrete methods from traits.") + + val XmixinForceForwarders = ChoiceSetting( + name = "-Xmixin-force-forwarders", + helpArg = "mode", + descr = "Generate forwarder methods in classes inhering concrete methods from traits.", + choices = List("true", "junit", "false"), + default = "junit", + choicesHelp = List( + "Always generate mixin forwarders.", + "Generate mixin forwarders for JUnit-annotated methods (JUnit 4 does not support default methods).", + "Only generate mixin forwarders required for program correctness.")) + + object mixinForwarderChoices { + def isTruthy = XmixinForceForwarders.value == "true" + def isJunit = isTruthy || XmixinForceForwarders.value == "junit" + } // XML parsing options object XxmlSettings extends MultiChoiceEnumeration { diff --git a/src/compiler/scala/tools/nsc/settings/Warnings.scala b/src/compiler/scala/tools/nsc/settings/Warnings.scala index 047ea3c751..839e734abc 100644 --- a/src/compiler/scala/tools/nsc/settings/Warnings.scala +++ b/src/compiler/scala/tools/nsc/settings/Warnings.scala @@ -25,8 +25,6 @@ trait Warnings { // currently considered too noisy for general use val warnUnusedImport = BooleanSetting("-Ywarn-unused-import", "Warn when imports are unused.") - val junitTraitMethodsNoForwarders = BooleanSetting("-Yjunit-trait-methods-no-forwarders", "Don't generate forwarders for JUnit annotated trait methods (JUnit 4 does not support default methods).") - // Experimental lint warnings that are turned off, but which could be turned on programmatically. // They are not activated by -Xlint and can't be enabled on the command line because they are not // created using the standard factory methods. diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 58f32b9aca..af9ba7c300 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -287,14 +287,14 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL { } def generateJUnitForwarder: Boolean = { - !settings.junitTraitMethodsNoForwarders && + settings.mixinForwarderChoices.isJunit && member.annotations.nonEmpty && JUnitAnnotations.exists(annot => annot.exists && member.hasAnnotation(annot)) } if (existsCompetingMethod(clazz.baseClasses) || generateJUnitForwarder) genForwarder(required = true) - else if (settings.XgenMixinForwarders) + else if (settings.mixinForwarderChoices.isTruthy) genForwarder(required = false) } diff --git a/test/junit/scala/lang/traits/BytecodeTest.scala b/test/junit/scala/lang/traits/BytecodeTest.scala index c20fae2500..7bfa3362d4 100644 --- a/test/junit/scala/lang/traits/BytecodeTest.scala +++ b/test/junit/scala/lang/traits/BytecodeTest.scala @@ -236,7 +236,7 @@ class BytecodeTest extends BytecodeTesting { |class C extends T """.stripMargin val List(c1, _) = compileClasses(code) - val List(c2, _) = newCompiler(extraArgs = "-Xgen-mixin-forwarders").compileClasses(code) + val List(c2, _) = newCompiler(extraArgs = "-Xmixin-force-forwarders:true").compileClasses(code) assert(getMethods(c1, "f").isEmpty) assertSameCode(getMethod(c2, "f"), List(VarOp(ALOAD, 0), Invoke(INVOKESTATIC, "T", "f$", "(LT;)I", true), Op(IRETURN))) @@ -278,11 +278,11 @@ class BytecodeTest extends BytecodeTesting { @Test def sd210(): Unit = { - val forwardersCompiler = newCompiler(extraArgs = "-Xgen-mixin-forwarders") + val forwardersCompiler = newCompiler(extraArgs = "-Xmixin-force-forwarders:true") val jCode = List("interface A { default int m() { return 1; } }" -> "A.java") - // used to crash in the backend (SD-210) under `-Xgen-mixin-forwarders` + // used to crash in the backend (SD-210) under `-Xmixin-force-forwarders:true` val code1 = """trait B1 extends A // called "B1" not "B" due to scala-dev#214 |class C extends B1 @@ -291,7 +291,7 @@ class BytecodeTest extends BytecodeTesting { val List(_, c1a) = compileClasses(code1, jCode) assert(getAsmMethods(c1a, "m").isEmpty) // ok, no forwarder - // here we test a warning. without `-Xgen-mixin-forwarders`, the forwarder would not be + // here we test a warning. without `-Xmixin-force-forwarders:true`, the forwarder would not be // generated, it is not necessary for correctness. val warn = "Unable to implement a mixin forwarder for method m in class C unless interface A is directly extended by class C" val List(_, c1b) = forwardersCompiler.compileClasses(code1, jCode, allowMessage = _.msg.contains(warn)) |