Skip to content

Commit 6ae2dd8

Browse files
committed
Merge pull request scala#4601 from som-snytt/issue/9377
SI-9377 ScalaVersion init no longer fails if versionless
2 parents 4bbae6e + 9fa18cc commit 6ae2dd8

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ object ScalaVersion {
7777

7878
def apply(versionString: String, errorHandler: String => Unit): ScalaVersion = {
7979
def error() = errorHandler(
80-
s"There was a problem parsing ${versionString}. " +
81-
"Versions should be in the form major[.minor[.revision]] " +
82-
"where each part is a positive number, as in 2.10.1. " +
83-
"The minor and revision parts are optional."
80+
s"Bad version (${versionString}) not major[.minor[.revision[-suffix]]]"
8481
)
8582

8683
def toInt(s: String) = s match {
@@ -97,6 +94,7 @@ object ScalaVersion {
9794

9895
versionString match {
9996
case "none" => NoScalaVersion
97+
case "" => NoScalaVersion
10098
case "any" => AnyScalaVersion
10199
case vpat(majorS, minorS, revS, buildS) =>
102100
SpecificScalaVersion(toInt(majorS), toInt(minorS), toInt(revS), toBuild(buildS))

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,14 @@ class ScalaVersionTest {
5656
assertThrows[NumberFormatException] { ScalaVersion("2-") }
5757
assertThrows[NumberFormatException] { ScalaVersion("2-.") } // scalacheck territory
5858
assertThrows[NumberFormatException] { ScalaVersion("any.7") }
59+
60+
assertThrows[NumberFormatException] ( ScalaVersion("2.11-ok"), _ ==
61+
"Bad version (2.11-ok) not major[.minor[.revision[-suffix]]]" )
62+
63+
}
64+
65+
// SI-9377
66+
@Test def `missing version is as good as none`() {
67+
assertEquals(NoScalaVersion, ScalaVersion(""))
5968
}
6069
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ class SettingsTest {
178178
check(expected = "2.12", "-Xsource:2.12")
179179
assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource"), _ == "-Xsource requires an argument, the syntax is -Xsource:<version>")
180180
assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource", "2.11"), _ == "-Xsource requires an argument, the syntax is -Xsource:<version>")
181-
assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource:2.invalid"), _ contains "There was a problem parsing 2.invalid")
181+
assertThrows[IllegalArgumentException](check(expected = "2.11", "-Xsource:2.invalid"), _ contains "Bad version (2.invalid)")
182182
}
183183
}

0 commit comments

Comments
 (0)