Skip to content

Commit 8253ee2

Browse files
committed
Check Override before looking for overridden
1 parent 0ebb4db commit 8253ee2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ object CheckUnused:
924924
!m.isTerm || m.isSelfSym || m.is(Method) && (m.owner == defn.AnyClass || m.owner == defn.ObjectClass)
925925
def isEffectivelyPrivate(using Context): Boolean =
926926
sym.is(Private, butNot = ParamAccessor)
927-
|| sym.owner.isAnonymousClass && !sym.nextOverriddenSymbol.exists
927+
|| sym.owner.isAnonymousClass && !sym.is(Override) && !sym.nextOverriddenSymbol.exists
928928
// pick the symbol the user wrote for purposes of tracking
929929
inline def userSymbol(using Context): Symbol=
930930
if sym.denot.is(ModuleClass) then sym.denot.companionModule else sym

tests/warn/i22896/J.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
public class J {
3+
private int i = 42;
4+
public int i() { return 27; }
5+
public String i(int j) { return "hello, world"; }
6+
}

tests/warn/i22896/s.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -Werror -Wunused:privates
2+
3+
def f =
4+
new J:
5+
override val i = -1 // nowarn, trust override
6+
7+
def g =
8+
new J:
9+
override def i = -1 // nowarn, trust override
10+
11+
def h =
12+
new J:
13+
override def i() = -1 // nowarn correctly matches signature

0 commit comments

Comments
 (0)