Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ object CheckUnused:
def checkPrivate(sym: Symbol, pos: SrcPos) =
if ctx.settings.WunusedHas.privates
&& !sym.isPrimaryConstructor
&& sym.is(Private, butNot = SelfName | Synthetic | CaseAccessor)
&& !sym.isOneOf(SelfName | Synthetic | CaseAccessor)
&& !sym.name.is(BodyRetainerName)
&& !sym.isSerializationSupport
&& !(sym.is(Mutable) && sym.isSetter && sym.owner.is(Trait)) // tracks sym.underlyingSymbol sibling getter
Expand Down Expand Up @@ -764,7 +764,7 @@ object CheckUnused:
for (sym, pos) <- infos.defs.iterator if !sym.hasAnnotation(defn.UnusedAnnot) do
if infos.refs(sym) then
checkUnassigned(sym, pos)
else if sym.is(Private, butNot = ParamAccessor) then
else if sym.isEffectivelyPrivate then
checkPrivate(sym, pos)
else if sym.is(Param, butNot = Given | Implicit) then
checkParam(sym, pos)
Expand Down Expand Up @@ -885,6 +885,9 @@ object CheckUnused:
sym.isClass && sym.info.allMembers.forall: d =>
val m = d.symbol
!m.isTerm || m.isSelfSym || m.is(Method) && (m.owner == defn.AnyClass || m.owner == defn.ObjectClass)
def isEffectivelyPrivate(using Context): Boolean =
sym.is(Private, butNot = ParamAccessor)
|| sym.owner.isAnonymousClass && !sym.nextOverriddenSymbol.exists

extension (sel: ImportSelector)
def boundTpe: Type = sel.bound match
Expand Down
3 changes: 2 additions & 1 deletion tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3494,7 +3494,7 @@ Text => empty
Language => Scala
Symbols => 12 entries
Occurrences => 33 entries
Diagnostics => 1 entries
Diagnostics => 2 entries
Synthetics => 4 entries

Symbols:
Expand Down Expand Up @@ -3550,6 +3550,7 @@ Diagnostics:
[14:20..14:23): [warning] Alphanumeric method foo is not declared infix; it should not be used as infix operator.
Instead, use method syntax .foo(...) or backticked identifier `foo`.
The latter can be rewritten automatically under -rewrite -source 3.4-migration.
[19:8..19:17): [warning] unused private member

Synthetics:
[12:2..12:6):user => reflectiveSelectable(*)
Expand Down
13 changes: 13 additions & 0 deletions tests/warn/i22681.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

//> using options -Wunused:all

trait T:
def t: Int

class C:
def f: Runnable { def u: Int } = new Runnable with T:
private def v = 42 // avoid g judged too trivial to warn
def run() = ()
def g = v // warn effectively private member is unused
def t = v // nowarn
def u = v // warn despite structural type (TODO work around the limitation, at least for this example)
Loading