Skip to content

Commit 78e41d2

Browse files
author
Som Snytt
committed
Reference to enclosing element is not a usage
1 parent d76229e commit 78e41d2

File tree

7 files changed

+24
-30
lines changed

7 files changed

+24
-30
lines changed

src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
120120
}
121121
}
122122

123-
@annotation.tailrec private def findSymbol[T](candidates: List[T], f: T => Symbol): Symbol = {
124-
if (candidates.isEmpty) NoSymbol
125-
else f(candidates.head) match {
126-
case NoSymbol => findSymbol(candidates.tail, f)
127-
case sym => sym
128-
}
129-
}
130123
private def hasNewParents(tree: Tree) = {
131124
val parents = tree.symbol.info.parents
132125
val prev = enteringPrevPhase(tree.symbol.info.parents)

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -576,15 +576,6 @@ abstract class UnCurry extends InfoTransform
576576
tree
577577
}
578578

579-
@tailrec def isThrowable(pat: Tree): Boolean = pat match {
580-
case Typed(Ident(nme.WILDCARD), tpt) =>
581-
tpt.tpe =:= ThrowableTpe
582-
case Bind(_, pat) =>
583-
isThrowable(pat)
584-
case _ =>
585-
false
586-
}
587-
588579
tree match {
589580
/* Some uncurry post transformations add members to templates.
590581
*

src/compiler/scala/tools/nsc/typechecker/RefChecks.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ abstract class RefChecks extends Transform {
126126

127127
defaultMethodNames.toList.distinct foreach { name =>
128128
val methods = clazz.info.findMember(name, 0L, requiredFlags = METHOD, stableOnly = false).alternatives
129-
def hasDefaultParam(tpe: Type): Boolean = tpe match {
130-
case MethodType(params, restpe) => (params exists (_.hasDefault)) || hasDefaultParam(restpe)
131-
case _ => false
132-
}
133129
val haveDefaults = methods.filter(sym => mexists(sym.info.paramss)(_.hasDefault) && !nme.isProtectedAccessorName(sym.name))
134130

135131
if (haveDefaults.lengthCompare(1) > 0) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
562562
case b @ Bind(n, _) if !atBounded(b) && n != nme.DEFAULT_CASE => patvars += b.symbol
563563
case _ =>
564564
}
565-
case _: RefTree if isExisting(sym) => targets += sym
565+
case _: RefTree => if (isExisting(sym) && !currentOwner.hasTransOwner(sym)) targets += sym
566566
case Assign(lhs, _) if isExisting(lhs.symbol) => setVars += lhs.symbol
567567
case Function(ps, _) if settings.warnUnusedParams && !t.isErrorTyped => params ++=
568568
ps.filterNot(p => atBounded(p) || p.symbol.isSynthetic).map(_.symbol)

src/reflect/scala/reflect/internal/Printers.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,8 @@ trait Printers extends api.Printers { self: SymbolTable =>
291291
protected def printCaseDef(tree: CaseDef) = {
292292
val CaseDef(pat, guard, body) = tree
293293
print("case ")
294-
@tailrec def patConstr(pat: Tree): Tree = pat match {
295-
case Apply(fn, args) => patConstr(fn)
296-
case _ => pat
297-
}
298-
299-
print(pat); printOpt(" if ", guard)
294+
print(pat)
295+
printOpt(" if ", guard)
300296
print(" => ", body)
301297
}
302298

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ class Boppy extends {
44
warn-unused-privates.scala:5: warning: private constructor in class Bippy is never used
55
private def this(c: Int) = this(c, c) // warn
66
^
7+
warn-unused-privates.scala:6: warning: private method bippy in class Bippy is never used
8+
private def bippy(x: Int): Int = bippy(x) // warn
9+
^
710
warn-unused-privates.scala:7: warning: private method boop in class Bippy is never used
811
private def boop(x: Int) = x+a+b // warn
912
^
@@ -64,6 +67,9 @@ warn-unused-privates.scala:155: warning: private method y_= in class OtherNames
6467
warn-unused-privates.scala:269: warning: private val n in class t12992 enclosing def is unused is never used
6568
private val n = 42
6669
^
70+
warn-unused-privates.scala:274: warning: private method f in class recursive reference is not a usage is never used
71+
private def f(i: Int): Int = // warn
72+
^
6773
warn-unused-privates.scala:121: warning: private class Bar1 in object Types is never used
6874
private class Bar1 // warn
6975
^
@@ -76,12 +82,15 @@ warn-unused-privates.scala:233: warning: private class for your eyes only in obj
7682
warn-unused-privates.scala:249: warning: private class D in class nonprivate alias is enclosing is never used
7783
private class D extends C2 // warn
7884
^
85+
warn-unused-privates.scala:277: warning: private class P in class recursive reference is not a usage is never used
86+
private class P {
87+
^
7988
warn-unused-privates.scala:72: warning: local var s5 in class StableAccessors is never updated: consider using immutable val
8089
private[this] var s5 = 0 // warn, never set
8190
^
8291
warn-unused-privates.scala:114: warning: local var x in method f2 is never updated: consider using immutable val
8392
var x = 100 // warn about it being a var
8493
^
8594
error: No warnings can be incurred under -Werror.
86-
28 warnings
95+
31 warnings
8796
1 error

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//
2-
//> using options -deprecation -Wunused:privates -Xfatal-warnings
2+
//> using options -deprecation -Werror -Wunused:privates
33
//
44
class Bippy(a: Int, b: Int) {
55
private def this(c: Int) = this(c, c) // warn
6-
private def bippy(x: Int): Int = bippy(x) // TODO: could warn
6+
private def bippy(x: Int): Int = bippy(x) // warn
77
private def boop(x: Int) = x+a+b // warn
88
final private val MILLIS1 = 2000 // no warn, might have been inlined
99
final private val MILLIS2: Int = 1000 // warn
@@ -269,3 +269,12 @@ class `t12992 enclosing def is unused` {
269269
private val n = 42
270270
@annotation.unused def f() = n + 2 // unused code uses n
271271
}
272+
273+
class `recursive reference is not a usage` {
274+
private def f(i: Int): Int = // warn
275+
if (i <= 0) i
276+
else f(i-1)
277+
private class P {
278+
def f() = new P()
279+
}
280+
}

0 commit comments

Comments
 (0)