Skip to content

Commit c637007

Browse files
som-snytttgodzik
authored andcommitted
Check Override before looking for overridden
[Cherry-picked 8253ee2]
1 parent 61e34b6 commit c637007

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
@@ -923,7 +923,7 @@ object CheckUnused:
923923
}
924924
def isEffectivelyPrivate: Boolean =
925925
sym.is(Private, butNot = ParamAccessor)
926-
|| sym.owner.isAnonymousClass && !sym.nextOverriddenSymbol.exists
926+
|| sym.owner.isAnonymousClass && !sym.is(Override) && !sym.nextOverriddenSymbol.exists
927927
// pick the symbol the user wrote for purposes of tracking
928928
inline def userSymbol: Symbol=
929929
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)