Skip to content

Commit 8c00042

Browse files
author
Som Snytt
committed
More unused fixes
1 parent 060bc32 commit 8c00042

File tree

73 files changed

+281
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+281
-276
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ lazy val compiler = configureAsSubproject(project)
538538
).get
539539
},
540540
Compile / scalacOptions ++= Seq(
541-
//"-Wunused", "-Wnonunit-statement",
541+
//"-Wunused", //"-Wnonunit-statement",
542542
"-Wconf:cat=deprecation&msg=early initializers:s", // compiler heavily relies upon early initializers
543543
),
544544
Compile / doc / scalacOptions ++= Seq(

src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ abstract class DefaultMacroCompiler extends Resolvers
7171
val vanillaResult = tryCompile(vanillaImplRef)
7272
val bundleResult = tryCompile(bundleImplRef)
7373

74-
def ensureUnambiguousSuccess() = {
74+
def ensureUnambiguousSuccess(): Unit = {
7575
// we now face a hard choice of whether to report ambiguity:
7676
// 1) when there are eponymous methods in both bundle and object
7777
// 2) when both references to eponymous methods are resolved successfully
@@ -100,6 +100,7 @@ abstract class DefaultMacroCompiler extends Resolvers
100100
try {
101101
if (vanillaResult.isSuccess || bundleResult.isSuccess) ensureUnambiguousSuccess()
102102
if (vanillaResult.isFailure && bundleResult.isFailure) reportMostAppropriateFailure()
103+
//else // TODO
103104
vanillaResult.orElse(bundleResult).get
104105
} catch {
105106
case MacroImplResolutionException(pos, msg) =>

src/compiler/scala/reflect/reify/codegen/GenTypes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ trait GenTypes {
187187

188188
tpe match {
189189
case tpe @ RefinedType(parents, decls) =>
190-
reifySymDef(tpe.typeSymbol)
190+
List(tpe.typeSymbol).foreach(reifySymDef)
191191
mirrorBuildCall(nme.RefinedType, reify(parents), reifyScope(decls), reify(tpe.typeSymbol))
192192
case ExistentialType(tparams, underlying) =>
193193
tparams.foreach(reifySymDef)
194194
reifyBuildCall(nme.ExistentialType, tparams, underlying)
195195
case tpe @ ClassInfoType(parents, decls, clazz) =>
196-
reifySymDef(clazz)
196+
List(clazz).foreach(reifySymDef)
197197
mirrorBuildCall(nme.ClassInfoType, reify(parents), reifyScope(decls), reify(tpe.typeSymbol))
198198
case MethodType(params, restpe) =>
199199
params foreach reifySymDef

src/compiler/scala/reflect/reify/utils/SymbolTables.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
package scala.reflect.reify
1414
package utils
1515

16-
import scala.annotation.unused
16+
import scala.annotation._
1717
import scala.collection.{immutable, mutable}, mutable.{ArrayBuffer, ListBuffer}
1818
import java.lang.System.{lineSeparator => EOL}
1919

@@ -134,10 +134,11 @@ trait SymbolTables {
134134
s"""symtab = [$symtabString], aliases = [$aliasesString]${if (original.isDefined) ", has original" else ""}"""
135135
}
136136

137+
@nowarn // spurious unused buf.type
137138
def debugString: String = {
138139
val buf = new StringBuilder
139140
buf.append("symbol table = " + (if (syms.length == 0) "<empty>" else "")).append(EOL)
140-
syms foreach (sym => buf.append(symDef(sym)).append(EOL))
141+
syms.foreach(sym => buf.append(symDef(sym)).append(EOL))
141142
buf.delete(buf.length - EOL.length, buf.length)
142143
buf.toString
143144
}

src/compiler/scala/tools/nsc/ClassPathMemoryConsumptionTester.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ object ClassPathMemoryConsumptionTester {
4242
private def doTest(args: Array[String]) = {
4343
val settings = loadSettings(args.toList)
4444

45-
val mains = (1 to settings.requiredInstances.value) map (_ => new MainRetainsGlobal)
45+
val mains = (1 to settings.requiredInstances.value).map(_ => new MainRetainsGlobal)
4646

4747
// we need original settings without additional params to be able to use them later
4848
val baseArgs = argsWithoutRequiredInstances(args)
4949

5050
println(s"Loading classpath ${settings.requiredInstances.value} times")
5151
val startTime = System.currentTimeMillis()
5252

53-
mains map (_.process(baseArgs))
53+
mains.foreach(_.process(baseArgs))
5454

5555
val elapsed = System.currentTimeMillis() - startTime
5656
println(s"Operation finished - elapsed $elapsed ms")

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.io.{Closeable, FileNotFoundException, IOException}
1818
import java.net.URL
1919
import java.nio.charset.{Charset, CharsetDecoder, IllegalCharsetNameException, StandardCharsets, UnsupportedCharsetException}, StandardCharsets.UTF_8
2020

21-
import scala.annotation.{nowarn, tailrec}
21+
import scala.annotation._
2222
import scala.collection.{immutable, mutable}
2323
import scala.reflect.ClassTag
2424
import scala.reflect.internal.pickling.PickleBuffer
@@ -1470,6 +1470,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
14701470

14711471
private def showMembers() = {
14721472
// Allows for syntax like scalac -Xshow-class Random@erasure,typer
1473+
@nowarn
14731474
def splitClassAndPhase(str: String, term: Boolean): Name = {
14741475
def mkName(s: String) = if (term) newTermName(s) else newTypeName(s)
14751476
(str indexOf '@') match {

src/compiler/scala/tools/nsc/ast/NodePrinters.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ abstract class NodePrinters {
124124
}
125125
}
126126
def println(s: String) = printLine(s, "")
127+
def print(s: String) = buf.append(s)
127128

128129
def printLine(value: String, comment: String): Unit = {
129130
buf append " " * level
@@ -214,7 +215,7 @@ abstract class NodePrinters {
214215
}
215216

216217
def traverse(tree: Tree): Unit = {
217-
showPosition(tree)
218+
print(showPosition(tree))
218219

219220
tree match {
220221
case ApplyDynamic(fun, args) => applyCommon(tree, fun, args)
@@ -234,7 +235,7 @@ abstract class NodePrinters {
234235

235236
case ld @ LabelDef(name, params, rhs) =>
236237
printMultiline(tree) {
237-
showNameAndPos(ld)
238+
print(showNameAndPos(ld))
238239
traverseList("()", "params")(params)
239240
traverse(rhs)
240241
}

src/compiler/scala/tools/nsc/backend/jvm/opt/LocalOpt.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ object LocalOptImpls {
905905

906906
// Ensure the length of `renumber`. Unused variable indices are mapped to -1.
907907
val minLength = if (isWide) index + 2 else index + 1
908-
for (i <- renumber.length until minLength) renumber += -1
908+
for (_ <- renumber.length until minLength) renumber += -1
909909

910910
renumber(index) = index
911911
if (isWide) renumber(index + 1) = index
@@ -965,7 +965,7 @@ object LocalOptImpls {
965965
@tailrec
966966
def isEmpty(node: AbstractInsnNode): Boolean = node.getNext match {
967967
case null => true
968-
case l: LineNumberNode => true
968+
case _: LineNumberNode => true
969969
case n if n.getOpcode >= 0 => false
970970
case n => isEmpty(n)
971971
}

src/compiler/scala/tools/nsc/classpath/ClassPath.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
package scala.tools.nsc.classpath
1414

15+
import scala.annotation.unused
1516
import scala.reflect.io.AbstractFile
1617
import scala.tools.nsc.util.ClassRepresentation
1718

@@ -78,10 +79,10 @@ private[nsc] case class PackageEntryImpl(name: String) extends PackageEntry
7879

7980
private[nsc] trait NoSourcePaths {
8081
final def asSourcePathString: String = ""
81-
final private[nsc] def sources(inPackage: PackageName): Seq[SourceFileEntry] = Seq.empty
82+
final private[nsc] def sources(@unused inPackage: PackageName): Seq[SourceFileEntry] = Seq.empty
8283
}
8384

8485
private[nsc] trait NoClassPaths {
8586
final def findClassFile(className: String): Option[AbstractFile] = None
86-
private[nsc] final def classes(inPackage: PackageName): Seq[ClassFileEntry] = Seq.empty
87+
private[nsc] final def classes(@unused inPackage: PackageName): Seq[ClassFileEntry] = Seq.empty
8788
}

src/compiler/scala/tools/nsc/classpath/ZipAndJarFileLookupFactory.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ final class FileBasedCache[K, T] {
252252
if (disableCache) Left("caching is disabled due to a policy setting")
253253
else if (!checkStamps) Right(paths)
254254
else {
255-
val nonJarZips = urlsAndFiles.filter { case (url, file) => file == null || !Jar.isJarOrZip(file.file) }
255+
val nonJarZips = urlsAndFiles.filter { case (_, file) => file == null || !Jar.isJarOrZip(file.file) }
256256
if (nonJarZips.nonEmpty) Left(s"caching is disabled because of the following classpath elements: ${nonJarZips.map(_._1).mkString(", ")}.")
257257
else Right(paths)
258258
}
@@ -267,7 +267,7 @@ final class FileBasedCache[K, T] {
267267
val fileKey = attrs.fileKey()
268268
Stamp(lastModified, attrs.size(), if (fileKey == null) NoFileKey else fileKey)
269269
} catch {
270-
case ex: java.nio.file.NoSuchFileException =>
270+
case _: java.nio.file.NoSuchFileException =>
271271
// Dummy stamp for (currently) non-existent file.
272272
Stamp(FileTime.fromMillis(0), -1, new Object)
273273
}

src/compiler/scala/tools/nsc/fsc/CompileServer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class StandardCompileServer(fixPort: Int = 0) extends SocketServer(fixPort) {
152152
val c = compiler
153153
try new c.Run() compile command.files
154154
catch {
155-
case ex @ FatalError(msg) =>
155+
case FatalError(msg) =>
156156
reporter.error(null, "fatal error: " + msg)
157157
clearCompiler()
158158
case ex: Throwable =>

src/compiler/scala/tools/nsc/fsc/CompileSocket.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class CompileSocket extends CompileOutputCommon {
105105
if (portsDir.list.toList.exists(_.name == fixPort.toString)) fixPort else -1
106106
} else portsDir.list.toList match {
107107
case Nil => -1
108-
case x :: xs => try x.name.toInt catch {
108+
case x :: _ => try x.name.toInt catch {
109109
case e: Exception => x.delete() ; throw e
110110
}
111111
}
@@ -161,8 +161,8 @@ class CompileSocket extends CompileOutputCommon {
161161

162162
@tailrec
163163
def getsock(attempts: Int): Option[Socket] = attempts match {
164-
case 0 => warn("Unable to establish connection to compilation daemon") ; None
165-
case num =>
164+
case 0 => warn("Unable to establish connection to compilation daemon") ; None
165+
case _ =>
166166
val port = if (create) getPort(vmArgs) else pollPort()
167167
if (port < 0) return None
168168

src/compiler/scala/tools/nsc/fsc/ResidentScriptRunner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package scala.tools.nsc
1414
package fsc
1515

16+
import scala.annotation.unused
1617
import scala.reflect.io.Path
1718
import scala.util.control.NonFatal
1819

@@ -38,7 +39,7 @@ class ResidentScriptRunner(settings: GenericRunnerSettings) extends AbstractScri
3839
}
3940
}
4041

41-
final class DaemonKiller(settings: GenericRunnerSettings) extends ScriptRunner {
42+
final class DaemonKiller(@unused settings: GenericRunnerSettings) extends ScriptRunner {
4243
def runScript(script: String, scriptArgs: List[String]) = shutdownDaemon()
4344

4445
def runScriptText(script: String, scriptArgs: List[String]) = shutdownDaemon()

src/compiler/scala/tools/nsc/javac/JavaParsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
387387
* ElementValueList ::= ElementValue {`,` ElementValue}
388388
*/
389389
def annotation(): Tree = {
390-
object LiteralK { def unapply(token: Token) = tryLiteral() }
390+
object LiteralK { def unapply(@unused token: Token) = tryLiteral() }
391391

392392
def elementValue(): Tree = in.token match {
393393
case LiteralK(k) => in.nextToken(); atPos(in.currentPos)(Literal(k))

src/compiler/scala/tools/nsc/plugins/Plugins.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ trait Plugins { global: Global =>
9797
val cache = pluginClassLoadersCache
9898
val checkStamps = policy == settings.CachePolicy.LastModified.name
9999
cache.checkCacheability(classpath.map(_.toURL), checkStamps, disableCache) match {
100-
case Left(msg) =>
100+
case Left(_) =>
101101
val loader = newLoader()
102102
closeableRegistry.registerCloseable(loader)
103103
loader

src/compiler/scala/tools/nsc/profile/Profiler.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger
2222
import javax.management.openmbean.CompositeData
2323
import javax.management.{Notification, NotificationEmitter, NotificationListener}
2424

25-
import scala.annotation.nowarn
25+
import scala.annotation.{nowarn, unused}
2626
import scala.collection.mutable.ArrayBuffer
2727
import scala.reflect.internal.util.ChromeTrace
2828
import scala.reflect.io.AbstractFile
@@ -195,7 +195,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
195195
//we may miss a GC event if gc is occurring as we call this
196196
RealProfiler.gcMx foreach {
197197
case emitter: NotificationEmitter => emitter.removeNotificationListener(this)
198-
case gc =>
198+
case _ =>
199199
}
200200
reporter.close(this)
201201
if (chromeTrace != null) {
@@ -335,13 +335,12 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
335335
}
336336
}
337337

338-
private def completionName(root: Global#Symbol, associatedFile: AbstractFile): String = {
338+
private def completionName(root: Global#Symbol, @unused associatedFile: AbstractFile): String =
339339
if (root.hasPackageFlag || root.isTopLevel) root.javaBinaryNameString
340340
else {
341341
val enclosing = root.enclosingTopLevelClass
342342
enclosing.javaBinaryNameString + "::" + root.rawname.toString
343343
}
344-
}
345344
}
346345

347346
object EventType extends Enumeration {

src/compiler/scala/tools/nsc/profile/ThreadPoolFactory.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import java.util.concurrent.ThreadPoolExecutor.AbortPolicy
1616
import java.util.concurrent._
1717
import java.util.concurrent.atomic.AtomicInteger
1818

19+
import scala.annotation._
1920
import scala.tools.nsc.{Global, Phase}
2021

2122
sealed trait ThreadPoolFactory {
@@ -44,7 +45,7 @@ object ThreadPoolFactory {
4445
private def childGroup(name: String) = new ThreadGroup(baseGroup, name)
4546

4647
// Invoked when a new `Worker` is created, see `CommonThreadFactory.newThread`
47-
protected def wrapWorker(worker: Runnable, shortId: String): Runnable = worker
48+
protected def wrapWorker(worker: Runnable, @unused shortId: String): Runnable = worker
4849

4950
protected final class CommonThreadFactory(
5051
shortId: String,

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,11 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
286286

287287
/** Return the output directory for the given file.
288288
*/
289-
def outputDirFor(src: AbstractFile): AbstractFile = {
290-
def isBelow(srcDir: AbstractFile, outDir: AbstractFile) = src.path.startsWith(srcDir.path)
291-
292-
singleOutDir.getOrElse(outputs.find((isBelow _).tupled) match {
289+
def outputDirFor(src: AbstractFile): AbstractFile =
290+
singleOutDir.getOrElse(outputs.find { case (srcDir, _) => src.path.startsWith(srcDir.path) } match {
293291
case Some((_, d)) => d
294292
case _ => throw new FatalError(s"Could not find an output directory for ${src.path} in ${outputs}")
295293
})
296-
}
297294

298295
/** Return the source file path(s) which correspond to the given
299296
* classfile path and SourceFile attribute value, subject to the
@@ -312,19 +309,16 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
312309
* output directory there will be two or more candidate source file
313310
* paths.
314311
*/
315-
def srcFilesFor(classFile : AbstractFile, srcPath : String) : List[AbstractFile] = {
316-
def isBelow(srcDir: AbstractFile, outDir: AbstractFile) = classFile.path.startsWith(outDir.path)
317-
312+
def srcFilesFor(classFile : AbstractFile, srcPath : String) : List[AbstractFile] =
318313
singleOutDir match {
319314
case Some(_: VirtualDirectory | _: io.ZipArchive) => Nil
320315
case Some(d) => List(d.lookupPathUnchecked(srcPath, directory = false))
321316
case None =>
322-
(outputs filter (isBelow _).tupled) match {
317+
outputs.filter { case (_, outDir) => classFile.path.startsWith(outDir.path) } match {
323318
case Nil => Nil
324319
case matches => matches.map(_._1.lookupPathUnchecked(srcPath, directory = false))
325320
}
326321
}
327-
}
328322
}
329323

330324
/** A base class for settings of all types.
@@ -333,7 +327,7 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
333327
abstract class Setting(val name: String, val helpDescription: String) extends AbsSetting with SettingValue {
334328

335329
/** Will be called after this Setting is set for any extra work. */
336-
private[this] var _postSetHook: this.type => Unit = (x: this.type) => ()
330+
private[this] var _postSetHook: this.type => Unit = (_: this.type) => ()
337331
override def postSetHook(): Unit = _postSetHook(this)
338332
def withPostSetHook(f: this.type => Unit): this.type = { _postSetHook = f ; this }
339333

@@ -885,7 +879,7 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
885879
case List("help") => sawHelp = true; SomeOfNil
886880
case List(x) if choices contains x => value = x ; SomeOfNil
887881
case List(x) => errorAndValue("'" + x + "' is not a valid choice for '" + name + "'", None)
888-
case xs => errorAndValue("'" + name + "' does not accept multiple arguments.", None)
882+
case _ => errorAndValue("'" + name + "' does not accept multiple arguments.", None)
889883
}
890884
def unparse: List[String] =
891885
if (value == default) Nil else List(name + ":" + value)
@@ -915,14 +909,13 @@ class MutableSettings(val errorFn: String => Unit, val pathFactory: PathFactory)
915909
private[this] var _v: T = Nil
916910
private[this] var _numbs: List[(Int,Int)] = Nil
917911
private[this] var _names: T = Nil
918-
//protected var v: T = Nil
919912
protected def v: T = _v
920913
protected def v_=(t: T): Unit = {
921914
// throws NumberFormat on bad range (like -5-6)
922-
def asRange(s: String): (Int,Int) = (s indexOf '-') match {
915+
def asRange(s: String): (Int,Int) = s.indexOf('-') match {
923916
case -1 => (s.toInt, s.toInt)
924917
case 0 => (-1, s.tail.toInt)
925-
case i if s.last == '-' => (s.init.toInt, Int.MaxValue)
918+
case _ if s.last == '-' => (s.init.toInt, Int.MaxValue)
926919
case i => (s.take(i).toInt, s.drop(i+1).toInt)
927920
}
928921
val numsAndStrs = t filter (_.nonEmpty) partition (_ forall (ch => ch.isDigit || ch == '-'))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett
352352

353353
// Allows a specialised jar to be written. For instance one that provides stable hashing of content, or customisation of the file storage
354354
val YjarFactory = StringSetting ("-YjarFactory", "classname", "factory for jar files", classOf[DefaultJarFactory].getName)
355-
val YaddBackendThreads = IntSetting ("-Ybackend-parallelism", "maximum worker threads for backend", 1, Some((1,16)), (x: String) => None )
356-
val YmaxQueue = IntSetting ("-Ybackend-worker-queue", "backend threads worker queue size", 0, Some((0,1000)), (x: String) => None )
355+
val YaddBackendThreads = IntSetting ("-Ybackend-parallelism", "maximum worker threads for backend", 1, Some((1,16)), (_: String) => None )
356+
val YmaxQueue = IntSetting ("-Ybackend-worker-queue", "backend threads worker queue size", 0, Some((0,1000)), (_: String) => None )
357357
val YjarCompressionLevel = IntSetting("-Yjar-compression-level", "compression level to use when writing jar files",
358-
Deflater.DEFAULT_COMPRESSION, Some((Deflater.DEFAULT_COMPRESSION,Deflater.BEST_COMPRESSION)), (x: String) => None)
358+
Deflater.DEFAULT_COMPRESSION, Some((Deflater.DEFAULT_COMPRESSION,Deflater.BEST_COMPRESSION)), (_: String) => None)
359359
val YpickleJava = BooleanSetting("-Ypickle-java", "Pickler phase should compute pickles for .java defined symbols for use by build tools").internalOnly()
360360
val YpickleWrite = StringSetting("-Ypickle-write", "directory|jar", "destination for generated .sig files containing type signatures.", "", None).internalOnly()
361361
val YpickleWriteApiOnly = BooleanSetting("-Ypickle-write-api-only", "Exclude private members (other than those material to subclass compilation, such as private trait vals) from generated .sig files containing type signatures.").internalOnly()

0 commit comments

Comments
 (0)