Skip to content

Commit 221b87f

Browse files
committed
Fix test
[Cherry-picked 152a8cd][modified]
1 parent 245072f commit 221b87f

File tree

6 files changed

+146
-154
lines changed

6 files changed

+146
-154
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Trees {
3131

3232
/** Property key for backquoted identifiers and definitions */
3333
val Backquoted: Property.StickyKey[Unit] = Property.StickyKey()
34-
34+
3535
val SyntheticUnit: Property.StickyKey[Unit] = Property.StickyKey()
3636

3737
/** Trees take a parameter indicating what the type of their `tpe` field
@@ -765,6 +765,7 @@ object Trees {
765765
override def isEmpty: Boolean = !hasType
766766
override def toString: String =
767767
s"TypeTree${if (hasType) s"[$typeOpt]" else ""}"
768+
def isInferred = false
768769
}
769770

770771
/** Tree that replaces a level 1 splices in pickled (level 0) quotes.
@@ -787,6 +788,7 @@ object Trees {
787788
*/
788789
class InferredTypeTree[+T <: Untyped](implicit @constructorOnly src: SourceFile) extends TypeTree[T]:
789790
type ThisTree[+T <: Untyped] <: InferredTypeTree[T]
791+
override def isInferred = true
790792

791793
/** ref.type */
792794
case class SingletonTypeTree[+T <: Untyped] private[ast] (ref: Tree[T])(implicit @constructorOnly src: SourceFile)

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+20-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.config.ScalaSettings
77
import dotty.tools.dotc.core.Contexts.*
88
import dotty.tools.dotc.core.Flags.*
99
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}
1111
import dotty.tools.dotc.core.NameKinds.{ContextBoundParamName, ContextFunctionParamName, WildcardParamName}
1212
import dotty.tools.dotc.core.StdNames.nme
1313
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
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

0 commit comments

Comments
 (0)