diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index 61c18180420f..17d5a07bf18e 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -8,7 +8,8 @@ import dotty.tools.dotc.core.Contexts.* import dotty.tools.dotc.core.Flags.* import dotty.tools.dotc.core.Names.{Name, SimpleName, DerivedName, TermName, termName} import dotty.tools.dotc.core.NameOps.{isAnonymousFunctionName, isReplWrapperName, isContextFunction} -import dotty.tools.dotc.core.NameKinds.{BodyRetainerName, ContextBoundParamName, ContextFunctionParamName, WildcardParamName} +import dotty.tools.dotc.core.NameKinds.{ + BodyRetainerName, ContextBoundParamName, ContextFunctionParamName, DefaultGetterName, WildcardParamName} import dotty.tools.dotc.core.StdNames.nme import dotty.tools.dotc.core.Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule} import dotty.tools.dotc.core.Types.* @@ -173,7 +174,8 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha override def prepareForDefDef(tree: DefDef)(using Context): Context = def trivial = tree.symbol.is(Deferred) || isUnconsuming(tree.rhs) def nontrivial = tree.symbol.isConstructor || tree.symbol.isAnonymousFunction - if !nontrivial && trivial then + def isDefault = tree.symbol.name.is(DefaultGetterName) + if !nontrivial && trivial || isDefault then refInfos.skip.addOne(tree.symbol) if tree.symbol.is(Inline) then refInfos.inliners += 1 diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index f32b1fd5281c..cfbacf0589e1 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -547,7 +547,7 @@ class ReplDriver(settings: Array[String], try { val entries = flatten(jarFile) - val existingClass = entries.filter(_.ext.isClass).find(tryClassLoad(_).isDefined) + val existingClass = entries.filter(_.extension == "class").find(tryClassLoad(_).isDefined) if (existingClass.nonEmpty) out.println(s"The path '$path' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}") else inContext(state.context): diff --git a/tests/warn/i22746.scala b/tests/warn/i22746.scala new file mode 100644 index 000000000000..79576f5924be --- /dev/null +++ b/tests/warn/i22746.scala @@ -0,0 +1,21 @@ + +//> using options -Wunused:all -Werror + +import java.time.ZonedDateTime + +trait Foo[A] { + def apply(a: A, t: ZonedDateTime): A +} + +extension [A](a: A)(using f: Foo[A]) { + def foo(t: ZonedDateTime = ZonedDateTime.now): A = f(a, t) +} + +def test[I, A](in: I)( + run: I => Either[Throwable, A], + onErr: Throwable => Throwable = identity[Throwable] +): Either[Throwable, A] = + run(in) match { + case Left(t) => Left(onErr(t)) + case r @ Right(_) => r + }