Skip to content

Commit 4513caa

Browse files
committed
Ignore params to default arg getters
1 parent 977232c commit 4513caa

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ 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.{BodyRetainerName, ContextBoundParamName, ContextFunctionParamName, WildcardParamName}
11+
import dotty.tools.dotc.core.NameKinds.{
12+
BodyRetainerName, ContextBoundParamName, ContextFunctionParamName, DefaultGetterName, WildcardParamName}
1213
import dotty.tools.dotc.core.StdNames.nme
1314
import dotty.tools.dotc.core.Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule}
1415
import dotty.tools.dotc.core.Types.*
@@ -170,7 +171,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
170171
override def prepareForDefDef(tree: DefDef)(using Context): Context =
171172
def trivial = tree.symbol.is(Deferred) || isUnconsuming(tree.rhs)
172173
def nontrivial = tree.symbol.isConstructor || tree.symbol.isAnonymousFunction
173-
if !nontrivial && trivial then refInfos.skip.addOne(tree.symbol)
174+
def isDefault = tree.symbol.name.is(DefaultGetterName)
175+
if !nontrivial && trivial || isDefault then refInfos.skip.addOne(tree.symbol)
174176
if tree.symbol.is(Inline) then
175177
refInfos.inliners += 1
176178
else if !tree.symbol.is(Deferred) && tree.rhs.symbol != defn.Predef_undefined then

tests/warn/i22746.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
//> using options -Wunused:all -Werror
3+
4+
import java.time.ZonedDateTime
5+
6+
trait Foo[A] {
7+
def apply(a: A, t: ZonedDateTime): A
8+
}
9+
10+
extension [A](a: A)(using f: Foo[A]) {
11+
def foo(t: ZonedDateTime = ZonedDateTime.now): A = f(a, t)
12+
}
13+
14+
def test[I, A](in: I)(
15+
run: I => Either[Throwable, A],
16+
onErr: Throwable => Throwable = identity[Throwable]
17+
): Either[Throwable, A] =
18+
run(in) match {
19+
case Left(t) => Left(onErr(t))
20+
case r @ Right(_) => r
21+
}

0 commit comments

Comments
 (0)