Skip to content

Commit 2359cae

Browse files
committed
Nowarn extension taking params
1 parent a183140 commit 2359cae

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,11 @@ object CheckUnused:
548548
warnAt(pos)(UnusedSymbol.privateMembers)
549549
else if ctx.settings.WunusedHas.explicits
550550
&& !sym.is(Synthetic) // param to setter is unused bc there is no field yet
551-
&& !(sym.owner.is(ExtensionMethod) && {
552-
m.paramSymss.dropWhile(_.exists(_.isTypeParam)) match
553-
case (h :: Nil) :: Nil => h == sym // param is the extended receiver
551+
&& !(sym.owner.is(ExtensionMethod) &&
552+
m.paramSymss.dropWhile(_.exists(_.isTypeParam)).match
553+
case (h :: Nil) :: _ => h == sym // param is the extended receiver
554554
case _ => false
555-
})
555+
)
556556
&& !sym.name.isInstanceOf[DerivedName]
557557
&& !ctx.platform.isMainMethod(m)
558558
then

tests/warn/i23349.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//> using options -Wunused:explicits
2+
3+
// An external class that doesn't get its own `copy` method.
4+
class Foo(val a: String, val b: Int)
5+
6+
//
7+
// Example 1: add `copy` method via an extension method.
8+
//
9+
extension (self: Foo)
10+
def copy(a: String = self.a, b: Int = self.b): Foo = Foo(a, b) // nowarn
11+
12+
//
13+
// Example 2: implement `copyFoo` with parameter groups.
14+
//
15+
def copyFoo(foo: Foo)(a: String = foo.a, b: Int = foo.b): Foo = Foo(a, b) // warn

0 commit comments

Comments
 (0)