Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f9df67

Browse filesBrowse files
authored
Merge pull request #11031 from som-snytt/tweak/ff
Warn and remove obsolete constants and backticks
2 parents 244139f + 1d561f6 commit 8f9df67
Copy full SHA for 8f9df67

File tree

Expand file treeCollapse file tree

7 files changed

+92
-45
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+92
-45
lines changed

‎src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala

Copy file name to clipboardExpand all lines: src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala
+17-4Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
510510
val params = mutable.Set.empty[Symbol]
511511
val patvars = ListBuffer.empty[Tree /*Bind|ValDef*/]
512512

513+
val annots = mutable.Set.empty[AnnotationInfo] // avoid revisiting annotations of symbols and types
514+
513515
def recordReference(sym: Symbol): Unit = targets.addOne(sym)
514516

515517
def qualifiesTerm(sym: Symbol) = (
@@ -601,8 +603,13 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
601603
case _ =>
602604
}
603605

604-
if (t.tpe ne null) {
605-
for (tp <- t.tpe) if (!treeTypes(tp)) {
606+
def descend(annot: AnnotationInfo): Unit =
607+
if (!annots(annot)) {
608+
annots.addOne(annot)
609+
traverse(annot.original)
610+
}
611+
if ((t.tpe ne null) && t.tpe != NoType) {
612+
for (tp <- t.tpe if tp != NoType) if (!treeTypes(tp)) {
606613
// Include references to private/local aliases (which might otherwise refer to an enclosing class)
607614
val isAlias = {
608615
val td = tp.typeSymbolDirect
@@ -621,13 +628,20 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
621628
log(s"${if (isAlias) "alias " else ""}$tp referenced from $currentOwner")
622629
treeTypes += tp
623630
}
631+
for (annot <- tp.annotations)
632+
descend(annot)
624633
}
625634
// e.g. val a = new Foo ; new a.Bar ; don't let a be reported as unused.
626635
t.tpe.prefix foreach {
627636
case SingleType(_, sym) => recordReference(sym)
628637
case _ => ()
629638
}
630639
}
640+
641+
if (sym != null && sym.exists)
642+
for (annot <- sym.annotations)
643+
descend(annot)
644+
631645
super.traverse(t)
632646
}
633647
def isSuppressed(sym: Symbol): Boolean = sym.hasAnnotation(UnusedClass)
@@ -636,7 +650,7 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
636650
&& !isSuppressed(m)
637651
&& !m.isTypeParameterOrSkolem // would be nice to improve this
638652
&& (m.isPrivate || m.isLocalToBlock || isEffectivelyPrivate(m))
639-
&& !(treeTypes.exists(_.exists(_.typeSymbolDirect == m)))
653+
&& !treeTypes.exists(_.exists(_.typeSymbolDirect == m))
640654
)
641655
def isSyntheticWarnable(sym: Symbol) = {
642656
def privateSyntheticDefault: Boolean =
@@ -654,7 +668,6 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
654668
&& !targets(m)
655669
&& !(m.name == nme.WILDCARD) // e.g. val _ = foo
656670
&& (m.isValueParameter || !ignoreNames(m.name.toTermName)) // serialization/repl methods
657-
&& !isConstantType(m.info.resultType) // subject to constant inlining
658671
&& !treeTypes.exists(_ contains m) // e.g. val a = new Foo ; new a.Bar
659672
)
660673
def isUnusedParam(m: Symbol): Boolean = (

‎src/library/scala/collection/StringOps.scala

Copy file name to clipboardExpand all lines: src/library/scala/collection/StringOps.scala
+31-34Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ import scala.util.matching.Regex
2626
object StringOps {
2727
// just statics for companion class.
2828
private final val LF = 0x0A
29-
private final val FF = 0x0C
3029
private final val CR = 0x0D
31-
private final val SU = 0x1A
3230

3331
private class StringIterator(private[this] val s: String) extends AbstractIterator[Char] {
3432
private[this] var pos = 0
@@ -180,14 +178,14 @@ object StringOps {
180178
final class StringOps(private val s: String) extends AnyVal {
181179
import StringOps._
182180

183-
@`inline` def view: StringView = new StringView(s)
181+
@inline def view: StringView = new StringView(s)
184182

185-
@`inline` def size: Int = s.length
183+
@inline def size: Int = s.length
186184

187-
@`inline` def knownSize: Int = s.length
185+
@inline def knownSize: Int = s.length
188186

189187
/** Get the char at the specified index. */
190-
@`inline` def apply(i: Int): Char = s.charAt(i)
188+
@inline def apply(i: Int): Char = s.charAt(i)
191189

192190
def sizeCompare(otherSize: Int): Int = Integer.compare(s.length, otherSize)
193191

@@ -344,13 +342,13 @@ final class StringOps(private val s: String) extends AnyVal {
344342
* @return a new string which contains all chars
345343
* of this string followed by all chars of `suffix`.
346344
*/
347-
@`inline` def concat(suffix: String): String = s + suffix
345+
@inline def concat(suffix: String): String = s + suffix
348346

349347
/** Alias for `concat` */
350-
@`inline` def ++[B >: Char](suffix: Iterable[B]): immutable.IndexedSeq[B] = concat(suffix)
348+
@inline def ++[B >: Char](suffix: Iterable[B]): immutable.IndexedSeq[B] = concat(suffix)
351349

352350
/** Alias for `concat` */
353-
@`inline` def ++(suffix: IterableOnce[Char]): String = concat(suffix)
351+
@inline def ++(suffix: IterableOnce[Char]): String = concat(suffix)
354352

355353
/** Alias for `concat` */
356354
def ++(xs: String): String = concat(xs)
@@ -412,14 +410,14 @@ final class StringOps(private val s: String) extends AnyVal {
412410
}
413411

414412
/** Alias for `prepended` */
415-
@`inline` def +: [B >: Char] (elem: B): immutable.IndexedSeq[B] = prepended(elem)
413+
@inline def +: [B >: Char] (elem: B): immutable.IndexedSeq[B] = prepended(elem)
416414

417415
/** A copy of the string with an char prepended */
418416
def prepended(c: Char): String =
419417
new JStringBuilder(s.length + 1).append(c).append(s).toString
420418

421419
/** Alias for `prepended` */
422-
@`inline` def +: (c: Char): String = prepended(c)
420+
@inline def +: (c: Char): String = prepended(c)
423421

424422
/** A copy of the string with all elements from a collection prepended */
425423
def prependedAll[B >: Char](prefix: IterableOnce[B]): immutable.IndexedSeq[B] = {
@@ -432,13 +430,13 @@ final class StringOps(private val s: String) extends AnyVal {
432430
}
433431

434432
/** Alias for `prependedAll` */
435-
@`inline` def ++: [B >: Char] (prefix: IterableOnce[B]): immutable.IndexedSeq[B] = prependedAll(prefix)
433+
@inline def ++: [B >: Char] (prefix: IterableOnce[B]): immutable.IndexedSeq[B] = prependedAll(prefix)
436434

437435
/** A copy of the string with another string prepended */
438436
def prependedAll(prefix: String): String = prefix + s
439437

440438
/** Alias for `prependedAll` */
441-
@`inline` def ++: (prefix: String): String = prependedAll(prefix)
439+
@inline def ++: (prefix: String): String = prependedAll(prefix)
442440

443441
/** A copy of the string with an element appended */
444442
def appended[B >: Char](elem: B): immutable.IndexedSeq[B] = {
@@ -450,28 +448,28 @@ final class StringOps(private val s: String) extends AnyVal {
450448
}
451449

452450
/** Alias for `appended` */
453-
@`inline` def :+ [B >: Char](elem: B): immutable.IndexedSeq[B] = appended(elem)
451+
@inline def :+ [B >: Char](elem: B): immutable.IndexedSeq[B] = appended(elem)
454452

455453
/** A copy of the string with an element appended */
456454
def appended(c: Char): String =
457455
new JStringBuilder(s.length + 1).append(s).append(c).toString
458456

459457
/** Alias for `appended` */
460-
@`inline` def :+ (c: Char): String = appended(c)
458+
@inline def :+ (c: Char): String = appended(c)
461459

462460
/** A copy of the string with all elements from a collection appended */
463-
@`inline` def appendedAll[B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B] =
461+
@inline def appendedAll[B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B] =
464462
concat(suffix)
465463

466464
/** Alias for `appendedAll` */
467-
@`inline` def :++ [B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B] =
465+
@inline def :++ [B >: Char](suffix: IterableOnce[B]): immutable.IndexedSeq[B] =
468466
concat(suffix)
469467

470468
/** A copy of the string with another string appended */
471-
@`inline` def appendedAll(suffix: String): String = s + suffix
469+
@inline def appendedAll(suffix: String): String = s + suffix
472470

473471
/** Alias for `appendedAll` */
474-
@`inline` def :++ (suffix: String): String = s + suffix
472+
@inline def :++ (suffix: String): String = s + suffix
475473

476474
/** Produces a new collection where a slice of characters in this string is replaced by another collection.
477475
*
@@ -488,7 +486,7 @@ final class StringOps(private val s: String) extends AnyVal {
488486
*/
489487
def patch[B >: Char](from: Int, other: IterableOnce[B], replaced: Int): immutable.IndexedSeq[B] = {
490488
val len = s.length
491-
@`inline` def slc(off: Int, length: Int): WrappedString =
489+
@inline def slc(off: Int, length: Int): WrappedString =
492490
new WrappedString(s.substring(off, off+length))
493491
val b = immutable.IndexedSeq.newBuilder[B]
494492
val k = other.knownSize
@@ -645,8 +643,8 @@ final class StringOps(private val s: String) extends AnyVal {
645643

646644
// Note: String.repeat is added in JDK 11.
647645
/** Return the current string concatenated `n` times.
648-
*/
649-
def *(n: Int): String = {
646+
*/
647+
def *(n: Int): String =
650648
if (n <= 0) {
651649
""
652650
} else {
@@ -658,10 +656,9 @@ final class StringOps(private val s: String) extends AnyVal {
658656
}
659657
sb.toString
660658
}
661-
}
662659

663-
@`inline` private[this] def isLineBreak(c: Char) = c == CR || c == LF
664-
@`inline` private[this] def isLineBreak2(c0: Char, c: Char) = c0 == CR && c == LF
660+
@inline private def isLineBreak(c: Char) = c == CR || c == LF
661+
@inline private def isLineBreak2(c0: Char, c: Char) = c0 == CR && c == LF
665662

666663
/** Strip the trailing line separator from this string if there is one.
667664
* The line separator is taken as `"\n"`, `"\r"`, or `"\r\n"`.
@@ -698,7 +695,7 @@ final class StringOps(private val s: String) extends AnyVal {
698695

699696
private[this] val len = s.length
700697
private[this] var index = 0
701-
@`inline` private def done = index >= len
698+
@inline private def done = index >= len
702699
private def advance(): String = {
703700
val start = index
704701
while (!done && !isLineBreak(apply(index))) index += 1
@@ -1118,7 +1115,7 @@ final class StringOps(private val s: String) extends AnyVal {
11181115
* @return The result of applying `op` to `z` and all chars in this string,
11191116
* going left to right. Returns `z` if this string is empty.
11201117
*/
1121-
@`inline` def fold[A1 >: Char](z: A1)(op: (A1, A1) => A1): A1 = foldLeft(z)(op)
1118+
@inline def fold[A1 >: Char](z: A1)(op: (A1, A1) => A1): A1 = foldLeft(z)(op)
11221119

11231120
/** Selects the first char of this string.
11241121
* @return the first char of this string.
@@ -1158,19 +1155,19 @@ final class StringOps(private val s: String) extends AnyVal {
11581155
/** Stepper can be used with Java 8 Streams. This method is equivalent to a call to
11591156
* [[charStepper]]. See also [[codePointStepper]].
11601157
*/
1161-
@`inline` def stepper: IntStepper with EfficientSplit = charStepper
1158+
@inline def stepper: IntStepper with EfficientSplit = charStepper
11621159

11631160
/** Steps over characters in this string. Values are packed in `Int` for efficiency
11641161
* and compatibility with Java 8 Streams which have an efficient specialization for `Int`.
11651162
*/
1166-
@`inline` def charStepper: IntStepper with EfficientSplit = new CharStringStepper(s, 0, s.length)
1163+
@inline def charStepper: IntStepper with EfficientSplit = new CharStringStepper(s, 0, s.length)
11671164

11681165
/** Steps over code points in this string.
11691166
*/
1170-
@`inline` def codePointStepper: IntStepper with EfficientSplit = new CodePointStringStepper(s, 0, s.length)
1167+
@inline def codePointStepper: IntStepper with EfficientSplit = new CodePointStringStepper(s, 0, s.length)
11711168

11721169
/** Tests whether the string is not empty. */
1173-
@`inline` def nonEmpty: Boolean = !s.isEmpty
1170+
@inline def nonEmpty: Boolean = !s.isEmpty
11741171

11751172
/** Returns new sequence with elements in reversed order.
11761173
* @note $unicodeunaware
@@ -1268,7 +1265,7 @@ final class StringOps(private val s: String) extends AnyVal {
12681265
}
12691266

12701267
/** Selects all chars of this string which do not satisfy a predicate. */
1271-
@`inline` def filterNot(pred: Char => Boolean): String = filter(c => !pred(c))
1268+
@inline def filterNot(pred: Char => Boolean): String = filter(c => !pred(c))
12721269

12731270
/** Copy chars of this string to an array.
12741271
* Fills the given array `xs` starting at index 0.
@@ -1277,7 +1274,7 @@ final class StringOps(private val s: String) extends AnyVal {
12771274
*
12781275
* @param xs the array to fill.
12791276
*/
1280-
@`inline` def copyToArray(xs: Array[Char]): Int =
1277+
@inline def copyToArray(xs: Array[Char]): Int =
12811278
copyToArray(xs, 0, Int.MaxValue)
12821279

12831280
/** Copy chars of this string to an array.
@@ -1288,7 +1285,7 @@ final class StringOps(private val s: String) extends AnyVal {
12881285
* @param xs the array to fill.
12891286
* @param start the starting index.
12901287
*/
1291-
@`inline` def copyToArray(xs: Array[Char], start: Int): Int =
1288+
@inline def copyToArray(xs: Array[Char], start: Int): Int =
12921289
copyToArray(xs, start, Int.MaxValue)
12931290

12941291
/** Copy chars of this string to an array.

‎src/reflect/scala/reflect/internal/Flags.scala

Copy file name to clipboardExpand all lines: src/reflect/scala/reflect/internal/Flags.scala
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ class Flags extends ModifierFlags {
373373
private final val MODULE_PKL = (1L << 10)
374374
private final val INTERFACE_PKL = (1L << 11)
375375

376-
private final val PKL_MASK = 0x00000FFF
376+
//private final val PKL_MASK = 0x00000FFF
377377

378378
/** Pickler correspondence, ordered roughly by frequency of occurrence */
379379
private def rawPickledCorrespondence = Array[(Long, Long)](

‎src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala

Copy file name to clipboardExpand all lines: src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ trait StripMarginInterpolator {
4141
final def sm(args: Any*): String = impl('|', args: _*)
4242

4343
private final def impl(sep: Char, args: Any*): String = {
44-
def isLineBreak(c: Char) = c == '\n' || c == '\f' // compatible with StringOps#isLineBreak
44+
def isLineBreak(c: Char) = c == Chars.LF || c == Chars.FF // compatible with CharArrayReader
4545
def stripTrailingPart(s: String) = {
4646
val (pre, post) = s.span(c => !isLineBreak(c))
4747
pre + post.stripMargin(sep)

‎src/testkit/scala/tools/testkit/AssertUtil.scala

Copy file name to clipboardExpand all lines: src/testkit/scala/tools/testkit/AssertUtil.scala
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ object AssertUtil {
9292
def assertNotEqualsAny(message: => String, expected: Any, actual: Any): Unit =
9393
if (BoxesRunTime.equals(expected, actual)) assertNotEquals(message, expected, actual)
9494

95-
private final val timeout = 60 * 1000L // wait a minute
96-
9795
private implicit class `ref helper`[A <: AnyRef](val r: Reference[A]) extends AnyVal {
9896
def isEmpty: Boolean = r.get == null // r.refersTo(null) to avoid influencing collection
9997
def nonEmpty: Boolean = !isEmpty

‎test/files/neg/warn-unused-privates.check

Copy file name to clipboardExpand all lines: test/files/neg/warn-unused-privates.check
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ warn-unused-privates.scala:6: warning: private method bippy in class Bippy is ne
1010
warn-unused-privates.scala:7: warning: private method boop in class Bippy is never used
1111
private def boop(x: Int) = x+a+b // warn
1212
^
13+
warn-unused-privates.scala:8: warning: private val MILLIS1 in class Bippy is never used
14+
final private val MILLIS1 = 2000 // now warn, might have been inlined
15+
^
1316
warn-unused-privates.scala:9: warning: private val MILLIS2 in class Bippy is never used
1417
final private val MILLIS2: Int = 1000 // warn
1518
^
@@ -22,6 +25,9 @@ warn-unused-privates.scala:17: warning: private val BOOL in object Bippy is neve
2225
warn-unused-privates.scala:41: warning: private val hummer in class Boppy is never used
2326
private val hummer = "def" // warn
2427
^
28+
warn-unused-privates.scala:43: warning: private val bum in class Boppy is never used
29+
private final val bum = "ghi" // now warn, might have been (was) inlined
30+
^
2531
warn-unused-privates.scala:48: warning: private var v1 in trait Accessors is never used
2632
private var v1: Int = 0 // warn
2733
^
@@ -91,6 +97,9 @@ warn-unused-privates.scala:274: warning: private method f in class recursive ref
9197
warn-unused-privates.scala:277: warning: private class P in class recursive reference is not a usage is never used
9298
private class P {
9399
^
100+
warn-unused-privates.scala:284: warning: private val There in class Constantly is never used
101+
private final val There = "there" // warn
102+
^
94103
error: No warnings can be incurred under -Werror.
95-
31 warnings
104+
34 warnings
96105
1 error

‎test/files/neg/warn-unused-privates.scala

Copy file name to clipboardExpand all lines: test/files/neg/warn-unused-privates.scala
+32-2Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Bippy(a: Int, b: Int) {
55
private def this(c: Int) = this(c, c) // warn
66
private def bippy(x: Int): Int = bippy(x) // warn
77
private def boop(x: Int) = x+a+b // warn
8-
final private val MILLIS1 = 2000 // no warn, might have been inlined
8+
final private val MILLIS1 = 2000 // now warn, might have been inlined
99
final private val MILLIS2: Int = 1000 // warn
1010
final private val HI_COMPANION: Int = 500 // no warn, accessed from companion
1111
def hi() = Bippy.HI_INSTANCE
@@ -40,7 +40,7 @@ class Boppy extends {
4040
val dinger = hom
4141
private val hummer = "def" // warn
4242

43-
private final val bum = "ghi" // no warn, might have been (was) inlined
43+
private final val bum = "ghi" // now warn, might have been (was) inlined
4444
final val bum2 = "ghi" // no warn, same
4545
}
4646

@@ -278,3 +278,33 @@ class `recursive reference is not a usage` {
278278
def f() = new P()
279279
}
280280
}
281+
282+
class Constantly {
283+
private final val Here = "here"
284+
private final val There = "there" // warn
285+
def bromide = Here + " today, gone tomorrow."
286+
}
287+
288+
class Annots {
289+
import annotation._
290+
291+
trait T {
292+
def value: Int
293+
}
294+
295+
class C {
296+
private final val Here = "here"
297+
private final val There = "msg=there"
298+
def f(implicit @implicitNotFound(Here) t: T) = t.value
299+
def x: String @nowarn(There) = ""
300+
}
301+
302+
// cf HashMap#mergeInto which looped on type of new unchecked
303+
// case bm: BitmapIndexedMapNode[K, V] @unchecked =>
304+
class Weird[K, V] {
305+
def f(other: Weird[K, V]) =
306+
other match {
307+
case weird: Weird[K, V] @unchecked =>
308+
}
309+
}
310+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.