@@ -7,7 +7,7 @@ import dotty.tools.dotc.config.ScalaSettings
7
7
import dotty .tools .dotc .core .Contexts .*
8
8
import dotty .tools .dotc .core .Flags .*
9
9
import dotty .tools .dotc .core .Names .{Name , SimpleName , DerivedName , TermName , termName }
10
- import dotty .tools .dotc .core .NameOps .{isAnonymousFunctionName , isReplWrapperName }
10
+ import dotty .tools .dotc .core .NameOps .{isAnonymousFunctionName , isReplWrapperName , isContextFunction }
11
11
import dotty .tools .dotc .core .NameKinds .{ContextBoundParamName , ContextFunctionParamName , WildcardParamName }
12
12
import dotty .tools .dotc .core .StdNames .nme
13
13
import dotty .tools .dotc .core .Symbols .{ClassSymbol , NoSymbol , Symbol , defn , isDeprecated , requiredClass , requiredModule }
@@ -123,7 +123,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
123
123
override def transformTypeTree (tree : TypeTree )(using Context ): tree.type =
124
124
tree.tpe match
125
125
case AnnotatedType (_, annot) => transformAllDeep(annot.tree)
126
- case tpt if tpt.typeSymbol.exists => resolveUsage(tpt.typeSymbol, tpt.typeSymbol.name, NoPrefix )
126
+ case tpt if ! tree.isInferred && tpt.typeSymbol.exists => resolveUsage(tpt.typeSymbol, tpt.typeSymbol.name, NoPrefix )
127
127
case _ =>
128
128
tree
129
129
@@ -557,7 +557,7 @@ object CheckUnused:
557
557
val dd = defn
558
558
m.isDeprecated
559
559
|| m.is(Synthetic )
560
- || sym.name.is( ContextFunctionParamName ) // a ubiquitous parameter
560
+ || sym.owner. name.isContextFunction // a ubiquitous parameter
561
561
|| sym.name.is(ContextBoundParamName ) && sym.info.typeSymbol.isMarkerTrait // a ubiquitous parameter
562
562
|| m.hasAnnotation(dd.UnusedAnnot ) // param of unused method
563
563
|| sym.info.typeSymbol.match // more ubiquity
@@ -569,13 +569,17 @@ object CheckUnused:
569
569
|| sym.info.isInstanceOf [RefinedType ] // can't be expressed as a context bound
570
570
if ctx.settings.WunusedHas .implicits
571
571
&& ! infos.skip(m)
572
+ && ! m.isEffectivelyOverride
572
573
&& ! allowed
573
574
then
574
575
if m.isPrimaryConstructor then
575
576
val alias = m.owner.info.member(sym.name)
576
577
if alias.exists then
577
578
val aliasSym = alias.symbol
578
- if aliasSym.is(ParamAccessor ) && ! infos.refs(alias.symbol) then
579
+ val checking =
580
+ aliasSym.isAllOf(PrivateParamAccessor , butNot = CaseAccessor )
581
+ || aliasSym.isAllOf(Protected | ParamAccessor , butNot = CaseAccessor ) && m.owner.is(Given )
582
+ if checking && ! infos.refs(alias.symbol) then
579
583
warnAt(pos)(UnusedSymbol .implicitParams)
580
584
else
581
585
warnAt(pos)(UnusedSymbol .implicitParams)
@@ -845,17 +849,24 @@ object CheckUnused:
845
849
private val serializationNames : Set [TermName ] =
846
850
Set (" readResolve" , " readObject" , " readObjectNoData" , " writeObject" , " writeReplace" ).map(termName(_))
847
851
848
- extension (sym : Symbol )
849
- def isSerializationSupport ( using Context ) : Boolean =
852
+ extension (sym : Symbol )( using Context )
853
+ def isSerializationSupport : Boolean =
850
854
sym.is(Method ) && serializationNames(sym.name.toTermName) && sym.owner.isClass
851
855
&& sym.owner.derivesFrom(defn.JavaSerializableClass )
852
- def isCanEqual ( using Context ) : Boolean =
856
+ def isCanEqual : Boolean =
853
857
sym.isOneOf(GivenOrImplicit ) && sym.info.finalResultType.baseClasses.exists(_.derivesFrom(defn.CanEqualClass ))
854
- def isMarkerTrait ( using Context ) : Boolean =
858
+ def isMarkerTrait : Boolean =
855
859
sym.isClass && sym.info.allMembers.forall: d =>
856
860
val m = d.symbol
857
861
! m.isTerm || m.isSelfSym || m.is(Method ) && (m.owner == defn.AnyClass || m.owner == defn.ObjectClass )
858
-
862
+ def isEffectivelyOverride : Boolean =
863
+ sym.is(Override )
864
+ ||
865
+ sym.canMatchInheritedSymbols && { // inline allOverriddenSymbols using owner.info or thisType
866
+ val owner = sym.owner.asClass
867
+ val base = if owner.classInfo.selfInfo != NoType then owner.thisType else owner.info
868
+ base.baseClasses.drop(1 ).iterator.exists(sym.overriddenSymbol(_).exists)
869
+ }
859
870
extension (sel : ImportSelector )
860
871
def boundTpe : Type = sel.bound match
861
872
case untpd.TypedSplice (tree) => tree.tpe
0 commit comments