Skip to content

Ignore params to default arg getters #22749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
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.*
Expand Down Expand Up @@ -175,7 +176,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
Expand Down
21 changes: 21 additions & 0 deletions tests/warn/i22746.scala
Original file line number Diff line number Diff line change
@@ -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
}
Loading