From bad61ce0ff9f460c2f8873c134a7f6bee0a53824 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 6 Apr 2017 18:13:22 -0700 Subject: SD-363 Xlint no warn deprecated params, defaults Deprecation is an escape hatch for unused params. Since default arg getters receive values of previous args, don't warn when they are unused. --- .../scala/tools/nsc/typechecker/TypeDiagnostics.scala | 14 ++++++++++---- test/files/pos/t8040.scala | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 7013c7da93..a0139937f1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -567,10 +567,16 @@ trait TypeDiagnostics { && !treeTypes.exists(_ contains m) // e.g. val a = new Foo ; new a.Bar //&& !(m.isVal && m.info.resultType =:= typeOf[Unit]) // Unit val is uninteresting ) - def isUnusedParam(m: Symbol): Boolean = isUnusedTerm(m) && !(m.isParamAccessor && ( - m.owner.isImplicit || - targets.exists(s => s.isParameter && s.name == m.name && s.owner.isConstructor && s.owner.owner == m.owner) // exclude ctor params - )) + def isUnusedParam(m: Symbol): Boolean = ( + isUnusedTerm(m) + && !m.isDeprecated + && !m.owner.isDefaultGetter + && !(m.isParamAccessor && ( + m.owner.isImplicit || + targets.exists(s => s.isParameter + && s.name == m.name && s.owner.isConstructor && s.owner.owner == m.owner) // exclude ctor params + )) + ) def sympos(s: Symbol): Int = if (s.pos.isDefined) s.pos.point else if (s.isTerm) s.asTerm.referenced.pos.point else -1 def treepos(t: Tree): Int = diff --git a/test/files/pos/t8040.scala b/test/files/pos/t8040.scala index 1d1a770060..3e01014ab4 100644 --- a/test/files/pos/t8040.scala +++ b/test/files/pos/t8040.scala @@ -5,4 +5,9 @@ object Test { } def f(implicit x: DummyImplicit) = 42 // no warn DummyImplicit + + + def f(x: Int)(y: Int = 1) = x + y // no warn default getter + + def g(@deprecated("","") x: Int) = 42 // no warn deprecated } -- cgit v1.2.3