Skip to content

Commit bcd91a1

Browse files
authored
Merge pull request #1600 from xuwei-k/scala-3-project-Werror
fix all warnings in Scala 3 projects
2 parents 6a13d42 + 96c30e6 commit bcd91a1

File tree

14 files changed

+32
-21
lines changed

14 files changed

+32
-21
lines changed

build.sbt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ def baseSettings: Seq[Setting[?]] = Seq(
9191
testFrameworks += new TestFramework("verify.runner.Framework"),
9292
compile / javacOptions ++= Seq("-Xlint", "-Xlint:-serial"),
9393
Test / publishArtifact := false,
94+
Compile / compile / scalacOptions ++= {
95+
scalaBinaryVersion.value match {
96+
case "3" =>
97+
Seq(
98+
"-Werror",
99+
)
100+
case _ =>
101+
Nil
102+
}
103+
},
94104
scalacOptions += {
95105
scalaBinaryVersion.value match {
96106
case "2.10" | "2.11" =>

internal/compiler-bridge-test/src/test/scala/sbt/internal/inc/CompilingSpecification.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
120120
* Only the names used in the last src file are returned.
121121
*/
122122
def extractUsedNamesFromSrc(sources: String*): Map[String, Set[String]] = {
123-
val (srcFiles, analysisCallback) = compileSrcs(sources: _*)
123+
val (srcFiles, analysisCallback) = compileSrcs(sources*)
124124
srcFiles
125125
.map { srcFile =>
126126
val classesInSrc = analysisCallback.classNames(srcFile).map(_._1)
@@ -134,7 +134,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
134134
* dependencies between snippets.
135135
*/
136136
def extractDependenciesFromSrcs(srcs: String*): ExtractedClassDependencies = {
137-
val (_, testCallback) = compileSrcs(srcs: _*)
137+
val (_, testCallback) = compileSrcs(srcs*)
138138

139139
val memberRefDeps = testCallback.classDependencies.toList collect {
140140
case (target, src, DependencyByMemberRef) => (src, target)
@@ -158,7 +158,7 @@ trait CompilingSpecification extends AbstractBridgeProviderTestkit {
158158
) ++ sys.env
159159
.get("LOCALAPPDATA")
160160
.map(s => "C_CACHE4" -> Paths.get(s.replace('\\', '/'), "Coursier/cache/v1"))
161-
.toList: _*
161+
.toList*
162162
)
163163

164164
lazy val emptyChanges: DependencyChanges = new DependencyChanges {

internal/compiler-bridge-test/src/test/scala/sbt/internal/inc/ExtractUsedNamesSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class ExtractUsedNamesSpecification
236236

237237
def findPatMatUsages(in: String): Set[String] = {
238238
val (_, callback) = compileSrcs(List(List(sealedClass, in)))
239-
val clientNames = callback.usedNamesAndScopes.filterKeys(!_.startsWith("base."))
239+
val clientNames = callback.usedNamesAndScopes.view.filterKeys(!_.startsWith("base.")).toMap
240240

241241
val names = clientNames.flatMap {
242242
case (_, usages) =>

internal/zinc-apiinfo/src/main/scala/xsbt/api/SameAPI.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ class SameAPI(includePrivate: Boolean, includeParamNames: Boolean) {
101101
): Boolean =
102102
debug(
103103
sameStrings(a.keySet, b.keySet),
104-
"\tDefinition strings differed (a: " + (a.keySet -- b.keySet) + ", b: " + (b.keySet -- a
104+
"\tDefinition strings differed (a: " + (a.keySet.toSet -- b.keySet) + ", b: " + (b.keySet
105+
.toSet -- a
105106
.keySet) + ")"
106107
) &&
107108
zippedEntries(a, b).forall(tupled(sameNamedDefinitions))

internal/zinc-apiinfo/src/test/scala/sbt/internal/inc/ClassCanonicalNameSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ClassCanonicalNameSpec extends AnyFlatSpec with Matchers with Diagrams {
116116
// Strip the shared prefix to the class name
117117
def strip(s: String) = {
118118
val prefix = "sbt.internal.inc.p"
119-
if (s startsWith prefix) s stripPrefix prefix drop 2
119+
if (s.startsWith(prefix)) s stripPrefix prefix drop 2
120120
else s
121121
}
122122
}

internal/zinc-apiinfo/src/test/scala/xsbt/api/NameHashingSpecification.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class NameHashingSpecification extends UnitSpec {
105105
val nameHashes2 = nameHashing.nameHashes(classBar2)
106106
assertNameHashEqualForRegularName("Bar", nameHashes1, nameHashes2)
107107
assertNameHashEqualForRegularName("foo", nameHashes1, nameHashes2)
108-
nameHashes1 namesIn UseScope.Default should not contain "bar"
109-
nameHashes2 namesIn UseScope.Default should contain("bar")
108+
nameHashes1.namesIn(UseScope.Default) should not contain "bar"
109+
nameHashes2.namesIn(UseScope.Default) should contain("bar")
110110
}
111111

112112
/**

internal/zinc-classpath/src/main/scala/sbt/internal/inc/classpath/ClasspathUtilities.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ object ClasspathUtil {
180180
makeString(paths, java.io.File.pathSeparator)
181181
private[sbt] def makeString(paths: Seq[Path], sep: String): String = {
182182
val separated = paths.map(_.toAbsolutePath.toString)
183-
separated.find(_ contains sep).foreach(p => sys.error(s"Path '$p' contains separator '$sep'"))
183+
separated.find(_.contains(sep)).foreach(p => sys.error(s"Path '$p' contains separator '$sep'"))
184184
separated.mkString(sep)
185185
}
186186

@@ -200,9 +200,9 @@ object ClasspathUtil {
200200
}
201201
val basePath = toAbsolutePath(base).normalize
202202
val filePath = toAbsolutePath(file).normalize
203-
if (filePath startsWith basePath) {
203+
if (filePath.startsWith(basePath)) {
204204
val relativePath =
205-
catching(classOf[IllegalArgumentException]) opt (basePath relativize filePath)
205+
catching(classOf[IllegalArgumentException]) opt (basePath.relativize(filePath))
206206
relativePath map (_.toString)
207207
} else None
208208
}

internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/JavaErrorParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class JavaErrorParser(relativeDir: File = new File(new File(".").getAbsolutePath
173173
private def findFileSource(f: String): String = {
174174
// If a file looks like an absolute path, leave it as is.
175175
def isAbsolute(f: String) =
176-
(f startsWith "/") || (f matches """[^\\]+:\\.*""")
176+
(f.startsWith("/")) || (f.matches("""[^\\]+:\\.*"""))
177177
// TODO - we used to use existence checks, that may be the right way to go
178178
if (isAbsolute(f)) f
179179
else (new File(relativeDir, f)).getAbsolutePath

internal/zinc-compile-core/src/main/scala/sbt/internal/inc/javac/LocalJava.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ final class LocalJavaCompiler(compiler: javax.tools.JavaCompiler) extends XJavaC
295295
val diagnostics = new DiagnosticsReporter(reporter)
296296

297297
/* Local Java compiler doesn't accept `-J<flag>` options, strip them. */
298-
val (invalidOptions, cleanedOptions) = options partition (_ startsWith "-J")
298+
val (invalidOptions, cleanedOptions) = options partition (_.startsWith("-J"))
299299
if (invalidOptions.nonEmpty) {
300300
log.warn("Javac is running in 'local' mode. These flags have been removed:")
301301
log.warn(invalidOptions.mkString("\t", ", ", ""))

internal/zinc-compile-core/src/test/scala/sbt/internal/inc/javac/JavaCompilerSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class JavaCompilerSpec extends UnitSpec with Diagrams {
190190
}
191191

192192
def messageMatches(p: Problem, lineno: Int, message: Option[String] = None): Boolean = {
193-
def messageCheck = message forall (message => p.message contains message)
193+
def messageCheck = message forall (message => p.message.contains(message))
194194
def lineNumberCheck = p.position.line.isPresent && (p.position.line.get == lineno)
195195
lineNumberCheck && messageCheck
196196
}
@@ -201,7 +201,7 @@ class JavaCompilerSpec extends UnitSpec with Diagrams {
201201
colno: Int,
202202
lineContent: Option[String] = None
203203
): Boolean = {
204-
def lineContentCheck = lineContent forall (content => p.position.lineContent contains content)
204+
def lineContentCheck = lineContent forall (content => p.position.lineContent.contains(content))
205205
def lineNumberCheck = p.position.line.isPresent && (p.position.line.get == lineno)
206206
def columnCheck = p.position.pointer.isPresent && (p.position.pointer.get == colno)
207207
lineNumberCheck && columnCheck && lineContentCheck

0 commit comments

Comments
 (0)