@@ -7,7 +7,7 @@ import dotty.tools.dotc.config.ScalaSettings
77import dotty .tools .dotc .core .Contexts .*
88import dotty .tools .dotc .core .Flags .*
99import 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 }
1111import dotty .tools .dotc .core .NameKinds .{ContextBoundParamName , ContextFunctionParamName , WildcardParamName }
1212import dotty .tools .dotc .core .StdNames .nme
1313import 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
123123 override def transformTypeTree (tree : TypeTree )(using Context ): tree.type =
124124 tree.tpe match
125125 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 )
127127 case _ =>
128128 tree
129129
@@ -557,7 +557,7 @@ object CheckUnused:
557557 val dd = defn
558558 m.isDeprecated
559559 || m.is(Synthetic )
560- || sym.name.is( ContextFunctionParamName ) // a ubiquitous parameter
560+ || sym.owner. name.isContextFunction // a ubiquitous parameter
561561 || sym.name.is(ContextBoundParamName ) && sym.info.typeSymbol.isMarkerTrait // a ubiquitous parameter
562562 || m.hasAnnotation(dd.UnusedAnnot ) // param of unused method
563563 || sym.info.typeSymbol.match // more ubiquity
@@ -569,13 +569,17 @@ object CheckUnused:
569569 || sym.info.isInstanceOf [RefinedType ] // can't be expressed as a context bound
570570 if ctx.settings.WunusedHas .implicits
571571 && ! infos.skip(m)
572+ && ! m.isEffectivelyOverride
572573 && ! allowed
573574 then
574575 if m.isPrimaryConstructor then
575576 val alias = m.owner.info.member(sym.name)
576577 if alias.exists then
577578 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
579583 warnAt(pos)(UnusedSymbol .implicitParams)
580584 else
581585 warnAt(pos)(UnusedSymbol .implicitParams)
@@ -845,17 +849,24 @@ object CheckUnused:
845849 private val serializationNames : Set [TermName ] =
846850 Set (" readResolve" , " readObject" , " readObjectNoData" , " writeObject" , " writeReplace" ).map(termName(_))
847851
848- extension (sym : Symbol )
849- def isSerializationSupport ( using Context ) : Boolean =
852+ extension (sym : Symbol )( using Context )
853+ def isSerializationSupport : Boolean =
850854 sym.is(Method ) && serializationNames(sym.name.toTermName) && sym.owner.isClass
851855 && sym.owner.derivesFrom(defn.JavaSerializableClass )
852- def isCanEqual ( using Context ) : Boolean =
856+ def isCanEqual : Boolean =
853857 sym.isOneOf(GivenOrImplicit ) && sym.info.finalResultType.baseClasses.exists(_.derivesFrom(defn.CanEqualClass ))
854- def isMarkerTrait ( using Context ) : Boolean =
858+ def isMarkerTrait : Boolean =
855859 sym.isClass && sym.info.allMembers.forall: d =>
856860 val m = d.symbol
857861 ! 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+ }
859870 extension (sel : ImportSelector )
860871 def boundTpe : Type = sel.bound match
861872 case untpd.TypedSplice (tree) => tree.tpe
@@ -893,7 +904,7 @@ object CheckUnused:
893904 else imp.expr.tpe.member(sel.name.toTermName).hasAltWith(_.symbol.isCanEqual)
894905
895906 extension (pos : SrcPos )
896- def isZeroExtentSynthetic : Boolean = pos.span.isSynthetic && pos.span.start == pos.span.end
907+ def isZeroExtentSynthetic : Boolean = pos.span.isSynthetic && pos.span.isZeroExtent
897908
898909 extension [A <: AnyRef ](arr : Array [A ])
899910 // returns `until` if not satisfied
0 commit comments