Skip to content

Commit 6539323

Browse files
committed
Add an error about Scala 2.12 not supported for toolkits
1 parent 295de6d commit 6539323

File tree

8 files changed

+200
-144
lines changed

8 files changed

+200
-144
lines changed

build.sc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,9 @@ object ci extends Module {
18371837

18381838
def checkScalaVersions() = T.command {
18391839
website.checkMainScalaVersions(os.pwd / "website" / "docs" / "reference" / "scala-versions.md")
1840-
website.checkScalaJsVersions(os.pwd / "website" / "docs" / "guides" / "advanced" / "scala-js.md")
1840+
website.checkScalaJsVersions(
1841+
os.pwd / "website" / "docs" / "guides" / "advanced" / "scala-js.md"
1842+
)
18411843
}
18421844
}
18431845

modules/build/src/test/scala/scala/build/tests/BuildTests.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,4 +951,28 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
951951
expect(maybeBuild.exists(_.success))
952952
}
953953
}
954+
955+
for (dirValue <- Seq("default", "typelevel:default"))
956+
test(s"error when toolkit $dirValue is used with Scala 2.12") {
957+
val testInputs = TestInputs(
958+
os.rel / "simple.sc" ->
959+
s"""//> using toolkit $dirValue
960+
|
961+
|val n = 2
962+
|println(s"n=$$n")
963+
|""".stripMargin
964+
)
965+
966+
val scala212Options = baseOptions.copy(
967+
scalaOptions = baseOptions.scalaOptions.copy(
968+
scalaVersion = Some(MaybeScalaVersion(Constants.defaultScala212Version)),
969+
scalaBinaryVersion = None
970+
),
971+
scriptOptions = ScriptOptions(Some(true))
972+
)
973+
974+
testInputs.withBuild(scala212Options, buildThreads, bloopConfigOpt) { (_, _, maybeBuild) =>
975+
expect(maybeBuild.left.exists(_.message.startsWith("Toolkits do not support Scala 2.12")))
976+
}
977+
}
954978
}

modules/cli/src/main/scala/scala/cli/commands/repl/Repl.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ object Repl extends ScalaCommand[ReplOptions] {
382382
logger.message("Dry run, not running REPL.")
383383
else {
384384
val depClassPathArgs: Seq[String] =
385-
if replArtifacts.depsClassPath.nonEmpty && !replArtifacts.replMainClass.startsWith("ammonite") then
385+
if replArtifacts.depsClassPath.nonEmpty && !replArtifacts.replMainClass.startsWith(
386+
"ammonite"
387+
)
388+
then
386389
Seq(
387390
"-classpath",
388391
replArtifacts.depsClassPath.map(_.toString).mkString(File.pathSeparator)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package scala.build.errors
2+
3+
import scala.build.Position
4+
5+
final class ToolkitVersionError(msg: String, positions: Seq[Position])
6+
extends BuildException(msg, positions)

modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala

Lines changed: 115 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,134 +1908,135 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
19081908
}
19091909
}
19101910

1911-
test("actionable diagnostics on deprecated using directives") {
1912-
val inputs = TestInputs(
1913-
os.rel / "test.sc" ->
1914-
"""//> using toolkit latest
1915-
|//> using test.toolkit typelevel:latest
1916-
|
1917-
|//> using lib org.typelevel::cats-core:2.6.1
1918-
|
1919-
|object Test extends App {
1920-
| println("Hello")
1921-
|}
1922-
|""".stripMargin
1923-
)
1924-
1925-
withBsp(inputs, Seq(".", "--actions=false")) { (root, localClient, remoteServer) =>
1926-
async {
1927-
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
1928-
val target = {
1929-
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
1930-
expect(targets.length == 2)
1931-
extractMainTargets(targets)
1932-
}
1911+
if (!actualScalaVersion.startsWith("2.12"))
1912+
test("actionable diagnostics on deprecated using directives") {
1913+
val inputs = TestInputs(
1914+
os.rel / "test.sc" ->
1915+
"""//> using toolkit latest
1916+
|//> using test.toolkit typelevel:latest
1917+
|
1918+
|//> using lib org.typelevel::cats-core:2.6.1
1919+
|
1920+
|object Test extends App {
1921+
| println("Hello")
1922+
|}
1923+
|""".stripMargin
1924+
)
19331925

1934-
val targetUri = TestUtil.normalizeUri(target.getUri)
1935-
checkTargetUri(root, targetUri)
1926+
withBsp(inputs, Seq(".", "--actions=false")) { (root, localClient, remoteServer) =>
1927+
async {
1928+
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
1929+
val target = {
1930+
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
1931+
expect(targets.length == 2)
1932+
extractMainTargets(targets)
1933+
}
19361934

1937-
val targets = List(target).asJava
1935+
val targetUri = TestUtil.normalizeUri(target.getUri)
1936+
checkTargetUri(root, targetUri)
19381937

1939-
val compileResp = await {
1940-
remoteServer
1941-
.buildTargetCompile(new b.CompileParams(targets))
1942-
.asScala
1943-
}
1944-
expect(compileResp.getStatusCode == b.StatusCode.OK)
1938+
val targets = List(target).asJava
19451939

1946-
val diagnosticsParams = {
1947-
val diagnostics = localClient.diagnostics()
1948-
.filter(_.getReset == false)
1949-
expect(diagnostics.size == 3)
1950-
val params = diagnostics.head
1951-
expect(params.getBuildTarget.getUri == targetUri)
1952-
expect(
1953-
TestUtil.normalizeUri(params.getTextDocument.getUri) ==
1954-
TestUtil.normalizeUri((root / "test.sc").toNIO.toUri.toASCIIString)
1955-
)
1956-
diagnostics
1957-
}
1940+
val compileResp = await {
1941+
remoteServer
1942+
.buildTargetCompile(new b.CompileParams(targets))
1943+
.asScala
1944+
}
1945+
expect(compileResp.getStatusCode == b.StatusCode.OK)
19581946

1959-
val diagnostics = diagnosticsParams.flatMap(_.getDiagnostics.asScala)
1960-
.sortBy(_.getRange().getEnd().getCharacter())
1947+
val diagnosticsParams = {
1948+
val diagnostics = localClient.diagnostics()
1949+
.filter(_.getReset == false)
1950+
expect(diagnostics.size == 3)
1951+
val params = diagnostics.head
1952+
expect(params.getBuildTarget.getUri == targetUri)
1953+
expect(
1954+
TestUtil.normalizeUri(params.getTextDocument.getUri) ==
1955+
TestUtil.normalizeUri((root / "test.sc").toNIO.toUri.toASCIIString)
1956+
)
1957+
diagnostics
1958+
}
19611959

1962-
{
1963-
checkDiagnostic(
1964-
diagnostic = diagnostics.apply(0),
1965-
expectedMessage =
1966-
"Using `latest` is deprecated, use `default` instead",
1967-
expectedSeverity = b.DiagnosticSeverity.WARNING,
1968-
expectedStartLine = 0,
1969-
expectedStartCharacter = 10,
1970-
expectedEndLine = 0,
1971-
expectedEndCharacter = 24
1972-
)
1960+
val diagnostics = diagnosticsParams.flatMap(_.getDiagnostics.asScala)
1961+
.sortBy(_.getRange().getEnd().getCharacter())
1962+
1963+
{
1964+
checkDiagnostic(
1965+
diagnostic = diagnostics.apply(0),
1966+
expectedMessage =
1967+
"Using `latest` is deprecated, use `default` instead",
1968+
expectedSeverity = b.DiagnosticSeverity.WARNING,
1969+
expectedStartLine = 0,
1970+
expectedStartCharacter = 10,
1971+
expectedEndLine = 0,
1972+
expectedEndCharacter = 24
1973+
)
19731974

1974-
checkScalaAction(
1975-
diagnostic = diagnostics.apply(0),
1976-
expectedActionsSize = 1,
1977-
expectedTitle = "Change to: toolkit default",
1978-
expectedChanges = 1,
1979-
expectedStartLine = 0,
1980-
expectedStartCharacter = 10,
1981-
expectedEndLine = 0,
1982-
expectedEndCharacter = 24,
1983-
expectedNewText = "toolkit default"
1984-
)
1985-
}
1975+
checkScalaAction(
1976+
diagnostic = diagnostics.apply(0),
1977+
expectedActionsSize = 1,
1978+
expectedTitle = "Change to: toolkit default",
1979+
expectedChanges = 1,
1980+
expectedStartLine = 0,
1981+
expectedStartCharacter = 10,
1982+
expectedEndLine = 0,
1983+
expectedEndCharacter = 24,
1984+
expectedNewText = "toolkit default"
1985+
)
1986+
}
19861987

1987-
{
1988-
checkDiagnostic(
1989-
diagnostic = diagnostics.apply(1),
1990-
expectedMessage =
1991-
"Using `latest` is deprecated, use `default` instead",
1992-
expectedSeverity = b.DiagnosticSeverity.WARNING,
1993-
expectedStartLine = 1,
1994-
expectedStartCharacter = 10,
1995-
expectedEndLine = 1,
1996-
expectedEndCharacter = 39
1997-
)
1988+
{
1989+
checkDiagnostic(
1990+
diagnostic = diagnostics.apply(1),
1991+
expectedMessage =
1992+
"Using `latest` is deprecated, use `default` instead",
1993+
expectedSeverity = b.DiagnosticSeverity.WARNING,
1994+
expectedStartLine = 1,
1995+
expectedStartCharacter = 10,
1996+
expectedEndLine = 1,
1997+
expectedEndCharacter = 39
1998+
)
19981999

1999-
checkScalaAction(
2000-
diagnostic = diagnostics.apply(1),
2001-
expectedActionsSize = 1,
2002-
expectedTitle = "Change to: test.toolkit typelevel:default",
2003-
expectedChanges = 1,
2004-
expectedStartLine = 1,
2005-
expectedStartCharacter = 10,
2006-
expectedEndLine = 1,
2007-
expectedEndCharacter = 39,
2008-
expectedNewText = "test.toolkit typelevel:default"
2009-
)
2010-
}
2000+
checkScalaAction(
2001+
diagnostic = diagnostics.apply(1),
2002+
expectedActionsSize = 1,
2003+
expectedTitle = "Change to: test.toolkit typelevel:default",
2004+
expectedChanges = 1,
2005+
expectedStartLine = 1,
2006+
expectedStartCharacter = 10,
2007+
expectedEndLine = 1,
2008+
expectedEndCharacter = 39,
2009+
expectedNewText = "test.toolkit typelevel:default"
2010+
)
2011+
}
20112012

2012-
{
2013-
checkDiagnostic(
2014-
diagnostic = diagnostics.apply(2),
2015-
expectedMessage =
2016-
"Using `lib` is deprecated, use `dep` instead",
2017-
expectedSeverity = b.DiagnosticSeverity.WARNING,
2018-
expectedStartLine = 3,
2019-
expectedStartCharacter = 10,
2020-
expectedEndLine = 3,
2021-
expectedEndCharacter = 44
2022-
)
2013+
{
2014+
checkDiagnostic(
2015+
diagnostic = diagnostics.apply(2),
2016+
expectedMessage =
2017+
"Using `lib` is deprecated, use `dep` instead",
2018+
expectedSeverity = b.DiagnosticSeverity.WARNING,
2019+
expectedStartLine = 3,
2020+
expectedStartCharacter = 10,
2021+
expectedEndLine = 3,
2022+
expectedEndCharacter = 44
2023+
)
20232024

2024-
checkScalaAction(
2025-
diagnostic = diagnostics.apply(2),
2026-
expectedActionsSize = 1,
2027-
expectedTitle = "Change to: dep org.typelevel::cats-core:2.6.1",
2028-
expectedChanges = 1,
2029-
expectedStartLine = 3,
2030-
expectedStartCharacter = 10,
2031-
expectedEndLine = 3,
2032-
expectedEndCharacter = 44,
2033-
expectedNewText = "dep org.typelevel::cats-core:2.6.1"
2034-
)
2025+
checkScalaAction(
2026+
diagnostic = diagnostics.apply(2),
2027+
expectedActionsSize = 1,
2028+
expectedTitle = "Change to: dep org.typelevel::cats-core:2.6.1",
2029+
expectedChanges = 1,
2030+
expectedStartLine = 3,
2031+
expectedStartCharacter = 10,
2032+
expectedEndLine = 3,
2033+
expectedEndCharacter = 44,
2034+
expectedNewText = "dep org.typelevel::cats-core:2.6.1"
2035+
)
2036+
}
20352037
}
20362038
}
20372039
}
2038-
}
20392040

20402041
private def checkIfBloopProjectIsInitialised(
20412042
root: os.Path,

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,13 +2166,14 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
21662166
}
21672167
}
21682168

2169-
test("toolkit default works") {
2169+
test("toolkit default") {
21702170
val inputs = TestInputs(
21712171
os.rel / "Main.scala" ->
21722172
"""//> using toolkit default
21732173
|//> using toolkit typelevel:default
21742174
|
2175-
|import cats.effect.*
2175+
|import cats.effect.IOApp
2176+
|import cats.effect.IO
21762177
|
21772178
|object Hello extends IOApp.Simple {
21782179
| def run = IO.println(os.pwd)
@@ -2181,8 +2182,16 @@ abstract class RunTestDefinitions(val scalaVersionOpt: Option[String])
21812182
)
21822183

21832184
inputs.fromRoot { root =>
2184-
val result = os.proc(TestUtil.cli, extraOptions, ".").call(cwd = root, check = true)
2185-
expect(result.out.trim() == root.toString)
2185+
val result =
2186+
os.proc(TestUtil.cli, extraOptions, ".").call(cwd = root, stderr = os.Pipe, check = false)
2187+
if (actualScalaVersion.startsWith("2.12")) {
2188+
expect(result.exitCode == 1)
2189+
expect(result.err.trim().contains("Toolkits do not support Scala 2.12"))
2190+
}
2191+
else {
2192+
expect(result.exitCode == 0)
2193+
expect(result.out.trim() == root.toString)
2194+
}
21862195
}
21872196
}
21882197

modules/integration/src/test/scala/scala/cli/integration/TestTestDefinitions.scala

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,29 @@ abstract class TestTestDefinitions(val scalaVersionOpt: Option[String])
733733
}
734734
}
735735

736-
test("toolkit") {
737-
successfulTestInputs(s"//> using toolkit ${Constants.toolkitVersion}").fromRoot { root =>
738-
val output = os.proc(TestUtil.cli, "test", extraOptions, ".").call(cwd = root).out.text()
739-
expect(output.contains("Hello from tests"))
736+
if (!actualScalaVersion.startsWith("2.12")) {
737+
test("toolkit") {
738+
successfulTestInputs(s"//> using toolkit ${Constants.toolkitVersion}").fromRoot { root =>
739+
val output = os.proc(TestUtil.cli, "test", extraOptions, ".").call(cwd = root).out.text()
740+
expect(output.contains("Hello from tests"))
741+
}
740742
}
741-
}
742743

743-
test("toolkit from command line") {
744-
successfulTestInputs("").fromRoot { root =>
745-
val output =
746-
os.proc(
747-
TestUtil.cli,
748-
"test",
749-
extraOptions,
750-
".",
751-
"--toolkit",
752-
Constants.toolkitVersion
753-
).call(cwd =
754-
root
755-
).out.text()
756-
expect(output.contains("Hello from tests"))
744+
test("toolkit from command line") {
745+
successfulTestInputs("").fromRoot { root =>
746+
val output =
747+
os.proc(
748+
TestUtil.cli,
749+
"test",
750+
extraOptions,
751+
".",
752+
"--toolkit",
753+
Constants.toolkitVersion
754+
).call(cwd =
755+
root
756+
).out.text()
757+
expect(output.contains("Hello from tests"))
758+
}
757759
}
758760
}
759761
}

0 commit comments

Comments
 (0)