Skip to content

Commit d75ca7f

Browse files
authored
Don't warn retainedBody (#22510)
Fixes #22507 Easy name-based check for private members.
2 parents 85ab75f + 8d3954f commit d75ca7f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ 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}
1010
import dotty.tools.dotc.core.NameOps.{isAnonymousFunctionName, isReplWrapperName}
11-
import dotty.tools.dotc.core.NameKinds.{ContextBoundParamName, ContextFunctionParamName, WildcardParamName}
11+
import dotty.tools.dotc.core.NameKinds.{BodyRetainerName, 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}
1414
import dotty.tools.dotc.core.Types.*
@@ -511,6 +511,7 @@ object CheckUnused:
511511
if ctx.settings.WunusedHas.privates
512512
&& !sym.isPrimaryConstructor
513513
&& sym.is(Private, butNot = SelfName | Synthetic | CaseAccessor)
514+
&& !sym.name.is(BodyRetainerName)
514515
&& !sym.isSerializationSupport
515516
&& !(sym.is(Mutable) && sym.isSetter && sym.owner.is(Trait)) // tracks sym.underlyingSymbol sibling getter
516517
then

Diff for: tests/warn/t22507.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
//> using options -Werror -Wunused:privates
3+
4+
case class BinaryFen(value: Array[Byte]) extends AnyVal:
5+
6+
def read: Unit =
7+
val reader = new Iterator[Byte]:
8+
val inner = value.iterator
9+
override inline def hasNext: Boolean = inner.hasNext // nowarn
10+
override inline def next: Byte = if hasNext then inner.next else 0.toByte // nowarn
11+
12+
if reader.hasNext then
13+
val b: Byte = reader.next
14+
println(b)

0 commit comments

Comments
 (0)