8000 Add Scala 3 aliases, limit release, adjust target · scala/scala@0a3a478 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a3a478

Browse files
committed
Add Scala 3 aliases, limit release, adjust target
1 parent 06d85a5 commit 0a3a478

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/compiler/scala/tools/nsc/settings/StandardScalaSettings.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ trait StandardScalaSettings { _: MutableSettings =>
6969
if (releaseValue.map(_.toInt < setting.value.toInt).getOrElse(false)) errorFn("-release cannot be less than -target")
7070
}
7171
.withAbbreviation("--target")
72+
.withAbbreviation("--Xtarget")
73+
.withAbbreviation("-Xtarget")
74+
.withAbbreviation("-Xunchecked-java-output-version")
7275
.withDeprecationMessage("Use -release instead to compile against the correct platform API.")
73-
def targetValue: String = target.valueSetByUser.orElse(releaseValue).getOrElse( 8000 target.value)
76+
def targetValue: String = releaseValue.getOrElse(target.value)
7477
val unchecked = BooleanSetting ("-unchecked", "Enable additional warnings where generated code depends on assumptions. See also -Wconf.") withAbbreviation "--unchecked" withPostSetHook { s =>
7578
if (s.value) Wconf.tryToSet(List(s"cat=unchecked:w"))
7679
else Wconf.tryToSet(List(s"cat=unchecked:s"))
@@ -84,6 +87,7 @@ trait StandardScalaSettings { _: MutableSettings =>
8487
// Support passe prefixes of -target values:
8588
// - `jvm-` (from back when we also had `msil`)
8689
// - `1.` (from back when Java 2 was a possibility)
90+
// Otherwise, `-release` could be `IntSetting`.
8791
private def normalizeTarget(in: String): String = {
8892
val jvmish = raw"jvm-(\d*)".r
8993
in match {
@@ -95,9 +99,12 @@ trait StandardScalaSettings { _: MutableSettings =>
9599
}
96100

97101
object StandardScalaSettings {
98-
// not final in case some separately compiled client code wanted to depend on updated values
99102
val MinTargetVersion = 8
100-
val MaxTargetVersion = 18
103+
val MaxTargetVersion = ScalaVersion(javaSpecVersion) match {
104+
case SpecificScalaVersion(1, minor, _, _) => minor
105+
case SpecificScalaVersion(major, _, _, _) => major
106+
case _ => 18
107+
}
101108

102109
private val AllTargetVersions = (MinTargetVersion to MaxTargetVersion).map(_.toString).to(List)
103110
}

test/junit/scala/tools/nsc/settings/TargetTest.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ import org.junit.runner.RunWith
1818
import org.junit.runners.JUnit4
1919

2020
import scala.collection.mutable.ListBuffer
21+
import scala.util.Properties.javaSpecVersion
2122

2223
@RunWith(classOf[JUnit4])
2324
class TargetTest {
2425

2526
@Test def testSettingTargetSetting(): Unit = {
26-
def check(in: String, expect: String) = {
27+
def check(in: String, expect: String) =
28+
javaSpecVersion match {
29+
case "1.8" => if (expect == "8") checkSuccess(in, expect) else checkFail(in)
30+
case jdk if jdk.toInt >= expect.toInt => checkSuccess(in, expect)
31+
case _ => checkFail(in)
32+
}
33+
def checkSuccess(in: String, expect: String) = {
2734
val settings = new Settings(err => fail(s"Error output: $err"))
2835
val (ok, _) = settings.processArgumentString(in)
2936
assertTrue(ok)
@@ -34,7 +41,7 @@ class TargetTest {
3441
val settings = new Settings(messages.addOne)
3542
val (ok, _) = settings.processArgumentString(in)
3643
assertFalse(ok)
37-
assertTrue(messages.nonEmpty)
44+
assertFalse(messages.isEmpty)
3845
assertEquals(2, messages.size) // bad choice + bad option
3946
assertTrue(messages.exists(_.startsWith("bad option")))
4047
}
@@ -46,7 +53,7 @@ class TargetTest {
4653

4754
check("-target:jvm-9", "9")
4855
check("-target:9", "9")
49-
// it's not Java 1.9, you reprobates!
56+
checkFail("-target:1.9") // it's not Java 1.9, you reprobates!
5057

5158
check("-target:jvm-10", "10")
5259
check("-target:10", "10")
@@ -72,7 +79,5 @@ class TargetTest {
7279
checkFail("-target:jvm-19") // not yet...
7380
checkFail("-target:jvm-3000") // not in our lifetime
7481
checkFail("-target:msil") // really?
75-
7682
}
77-
7883
}

0 commit comments

Comments
 (0)
0