Skip to content

Commit

Permalink
Add Scala 3 aliases, limit release, adjust target
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Mar 30, 2022
1 parent ffe7439 commit 3b14c5d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala
Expand Up @@ -69,8 +69,11 @@ trait StandardScalaSettings { _: MutableSettings =>
if (releaseValue.map(_.toInt < setting.value.toInt).getOrElse(false)) errorFn("-release cannot be less than -target")
}
.withAbbreviation("--target")
.withAbbreviation("--Xtarget")
.withAbbreviation("-Xtarget")
.withAbbreviation("-Xunchecked-java-output-version")
.withDeprecationMessage("Use -release instead to compile against the correct platform API.")
def targetValue: String = target.valueSetByUser.orElse(releaseValue).getOrElse(target.value)
def targetValue: String = releaseValue.getOrElse(target.value)
val unchecked = BooleanSetting ("-unchecked", "Enable additional warnings where generated code depends on assumptions. See also -Wconf.") withAbbreviation "--unchecked" withPostSetHook { s =>
if (s.value) Wconf.tryToSet(List(s"cat=unchecked:w"))
else Wconf.tryToSet(List(s"cat=unchecked:s"))
Expand All @@ -84,6 +87,7 @@ trait StandardScalaSettings { _: MutableSettings =>
// Support passe prefixes of -target values:
// - `jvm-` (from back when we also had `msil`)
// - `1.` (from back when Java 2 was a possibility)
// Otherwise, `-release` could be `IntSetting`.
private def normalizeTarget(in: String): String = {
val jvmish = raw"jvm-(\d*)".r
in match {
Expand All @@ -95,9 +99,12 @@ trait StandardScalaSettings { _: MutableSettings =>
}

object StandardScalaSettings {
// not final in case some separately compiled client code wanted to depend on updated values
val MinTargetVersion = 8
val MaxTargetVersion = 18
val MaxTargetVersion = ScalaVersion(javaSpecVersion) match {
case SpecificScalaVersion(1, minor, _, _) => minor
case SpecificScalaVersion(major, _, _, _) => major
case _ => 18
}

private val AllTargetVersions = (MinTargetVersion to MaxTargetVersion).map(_.toString).to(List)
}
15 changes: 10 additions & 5 deletions test/junit/scala/tools/nsc/settings/TargetTest.scala
Expand Up @@ -18,12 +18,19 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4

import scala.collection.mutable.ListBuffer
import scala.util.Properties.javaSpecVersion

@RunWith(classOf[JUnit4])
class TargetTest {

@Test def testSettingTargetSetting(): Unit = {
def check(in: String, expect: String) = {
def check(in: String, expect: String) =
javaSpecVersion match {
case "1.8" => if (expect == "8") checkSuccess(in, expect) else checkFail(in)
case jdk if jdk.toInt >= expect.toInt => checkSuccess(in, expect)
case _ => checkFail(in)
}
def checkSuccess(in: String, expect: String) = {
val settings = new Settings(err => fail(s"Error output: $err"))
val (ok, _) = settings.processArgumentString(in)
assertTrue(ok)
Expand All @@ -34,7 +41,7 @@ class TargetTest {
val settings = new Settings(messages.addOne)
val (ok, _) = settings.processArgumentString(in)
assertFalse(ok)
assertTrue(messages.nonEmpty)
assertFalse(messages.isEmpty)
assertEquals(2, messages.size) // bad choice + bad option
assertTrue(messages.exists(_.startsWith("bad option")))
}
Expand All @@ -46,7 +53,7 @@ class TargetTest {

check("-target:jvm-9", "9")
check("-target:9", "9")
// it's not Java 1.9, you reprobates!
checkFail("-target:1.9") // it's not Java 1.9, you reprobates!

check("-target:jvm-10", "10")
check("-target:10", "10")
Expand All @@ -72,7 +79,5 @@ class TargetTest {
checkFail("-target:jvm-19") // not yet...
checkFail("-target:jvm-3000") // not in our lifetime
checkFail("-target:msil") // really?

}

}

0 comments on commit 3b14c5d

Please sign in to comment.