Skip to content

Commit 4266b8f

Browse files
som-snytttgodzik
authored andcommitted
Ignore params to default arg getters
1 parent 6c39667 commit 4266b8f

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
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, isContextFunction}
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.*
@@ -173,7 +174,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
173174
override def prepareForDefDef(tree: DefDef)(using Context): Context =
174175
def trivial = tree.symbol.is(Deferred) || isUnconsuming(tree.rhs)
175176
def nontrivial = tree.symbol.isConstructor || tree.symbol.isAnonymousFunction
176-
if !nontrivial && trivial then
177+
def isDefault = tree.symbol.name.is(DefaultGetterName)
178+
if !nontrivial && trivial || isDefault then
177179
refInfos.skip.addOne(tree.symbol)
178180
if tree.symbol.is(Inline) then
179181
refInfos.inliners += 1

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ class ReplDriver(settings: Array[String],
547547
try {
548548
val entries = flatten(jarFile)
549549

550-
val existingClass = entries.filter(_.ext.isClass).find(tryClassLoad(_).isDefined)
550+
val existingClass = entries.filter(_.extension == "class").find(tryClassLoad(_).isDefined)
551551
if (existingClass.nonEmpty)
552552
out.println(s"The path '$path' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}")
553553
else inContext(state.context):

tests/warn/i22746.scala

Lines changed: 21 additions & 0 deletions
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)