From 833724b131f86b978f0831f637d386d7ca37a2aa Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 19 Oct 2016 12:09:40 -0700 Subject: SI-7860 No warn private implicit value class Previously, warned on unused synthetic companion. Also avoid false negative via hashcode reference to the underlying value. Avoid the synthetic conversion method for the implicit class (whose RHS always uses the class); the def itself is synthetic so is normally not warned. --- .../scala/tools/nsc/typechecker/TypeDiagnostics.scala | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index ee2d00900a..b30972f931 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -355,7 +355,10 @@ trait TypeDiagnostics { // functions to manipulate the name def preQualify() = modifyName(trueOwner.fullName + "." + _) - def postQualify() = if (!(postQualifiedWith contains trueOwner)) { postQualifiedWith ::= trueOwner; modifyName(_ + "(in " + trueOwner + ")") } + def postQualify() = if (!(postQualifiedWith contains trueOwner)) { + postQualifiedWith ::= trueOwner + modifyName(s => s"$s(in $trueOwner)") + } def typeQualify() = if (sym.isTypeParameterOrSkolem) postQualify() def nameQualify() = if (trueOwner.isPackageClass) preQualify() else postQualify() @@ -498,11 +501,13 @@ trait TypeDiagnostics { override def traverse(t: Tree): Unit = { t match { - case m: MemberDef if qualifies(t.symbol) => defnTrees += m + case m: MemberDef if qualifies(t.symbol) => + defnTrees += m t match { case DefDef(mods@_, name@_, tparams@_, vparamss, tpt@_, rhs@_) if !t.symbol.isAbstract && !t.symbol.isDeprecated => if (t.symbol.isPrimaryConstructor) for (cpa <- t.symbol.owner.constrParamAccessors if cpa.isPrivateLocal) params += cpa + else if (t.symbol.isSynthetic && t.symbol.isImplicit) return else if (!t.symbol.isConstructor) for (vs <- vparamss) params ++= vs.map(_.symbol) case _ => @@ -525,6 +530,7 @@ trait TypeDiagnostics { case NoType | NoPrefix => case NullaryMethodType(_) => case MethodType(_, _) => + case SingleType(_, _) => case _ => log(s"$tp referenced from $currentOwner") treeTypes += tp @@ -547,6 +553,7 @@ trait TypeDiagnostics { def isSyntheticWarnable(sym: Symbol) = ( sym.isDefaultGetter ) + def isUnusedTerm(m: Symbol): Boolean = ( (m.isTerm) && (!m.isSynthetic || isSyntheticWarnable(m)) @@ -562,7 +569,7 @@ trait TypeDiagnostics { def treepos(t: Tree): Int = if (t.pos.isDefined) t.pos.point else sympos(t.symbol) - def unusedTypes = defnTrees.toList filter (t => isUnusedType(t.symbol)) sortBy treepos + def unusedTypes = defnTrees.toList.filter(t => isUnusedType(t.symbol)).sortBy(treepos) def unusedTerms = { val all = defnTrees.toList.filter(v => isUnusedTerm(v.symbol)) -- cgit v1.2.3