Skip to content

Commit 14dd04b

Browse files
committed
Handle implicit params and adjust tests in WUnused
1 parent 6195663 commit 14dd04b

File tree

7 files changed

+52
-45
lines changed

7 files changed

+52
-45
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ object CheckUnused:
374374
def addIgnoredParam(sym: Symbol)(using Context): Unit =
375375
paramsToSkip += sym
376376

377-
378-
379377
/** Register an import */
380378
def registerImport(imp: tpd.Import)(using Context): Unit =
381379
if !tpd.languageImport(imp.expr).nonEmpty && !imp.isGeneratedByEnum && !isTransparentAndInline(imp) then
@@ -389,7 +387,8 @@ object CheckUnused:
389387
if memDef.isValidMemberDef then
390388
if memDef.isValidParam then
391389
if memDef.symbol.isOneOf(GivenOrImplicit) then
392-
implicitParamInScope += memDef
390+
if !paramsToSkip.contains(memDef.symbol) then
391+
implicitParamInScope += memDef
393392
else if !paramsToSkip.contains(memDef.symbol) then
394393
explicitParamInScope += memDef
395394
else if currScopeType.top == ScopeType.Local then

tests/neg-custom-args/fatal-warnings/i15503-scala2/scala2-t11681.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ trait BadAPI extends InterFace {
3333

3434
override def equals(other: Any): Boolean = true // OK
3535

36-
def i(implicit s: String) = answer // error
36+
def i(implicit s: String) = answer // ok
3737

3838
/*
3939
def future(x: Int): Int = {
@@ -63,7 +63,7 @@ case class CaseyKasem(k: Int) // OK
6363
case class CaseyAtTheBat(k: Int)(s: String) // error
6464

6565
trait Ignorance {
66-
def f(readResolve: Int) = answer // error
66+
def f(readResolve: Int) = answer // ok
6767
}
6868

6969
class Reusing(u: Int) extends Unusing(u) // OK
@@ -78,28 +78,28 @@ trait Unimplementation {
7878
}
7979

8080
trait DumbStuff {
81-
def f(implicit dummy: DummyImplicit) = answer // todo // error
82-
def g(dummy: DummyImplicit) = answer // error
81+
def f(implicit dummy: DummyImplicit) = answer // ok
82+
def g(dummy: DummyImplicit) = answer // ok
8383
}
8484
trait Proofs {
85-
def f[A, B](implicit ev: A =:= B) = answer // todo // error
86-
def g[A, B](implicit ev: A <:< B) = answer // todo // error
87-
def f2[A, B](ev: A =:= B) = answer // error
88-
def g2[A, B](ev: A <:< B) = answer // error
85+
def f[A, B](implicit ev: A =:= B) = answer // ok
86+
def g[A, B](implicit ev: A <:< B) = answer // ok
87+
def f2[A, B](ev: A =:= B) = answer // ok
88+
def g2[A, B](ev: A <:< B) = answer // ok
8989
}
9090

9191
trait Anonymous {
92-
def f = (i: Int) => answer // error
92+
def f = (i: Int) => answer // ok
9393

9494
def f1 = (_: Int) => answer // OK
9595

9696
def f2: Int => Int = _ + 1 // OK
9797

98-
def g = for (i <- List(1)) yield answer // error
98+
def g = for (i <- List(1)) yield answer // ok
9999
}
100100
trait Context[A]
101101
trait Implicits {
102-
def f[A](implicit ctx: Context[A]) = answer // error
102+
def f[A](implicit ctx: Context[A]) = answer // ok
103103
def g[A: Context] = answer // OK
104104
}
105105
class Bound[A: Context] // OK

tests/neg-custom-args/fatal-warnings/i15503e.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// scalac: -Wunused:explicits
22

3-
/* This goes around the "trivial method" detection */
4-
val default_val = 1
3+
object Foo {
4+
/* This goes around the "trivial method" detection */
5+
val default_val = 1
56

6-
def f1(a: Int) = a // OK
7-
def f2(a: Int) = default_val // error
8-
def f3(a: Int)(using Int) = a // OK
9-
def f4(a: Int)(using Int) = default_val // error
10-
def f6(a: Int)(using Int) = summon[Int] // error
11-
def f7(a: Int)(using Int) = summon[Int] + a // OK
7+
private def f1(a: Int) = a // OK
8+
private def f2(a: Int) = default_val // error
9+
private def f3(a: Int)(using Int) = a // OK
10+
private def f4(a: Int)(using Int) = default_val // error
11+
private def f6(a: Int)(using Int) = summon[Int] // error
12+
private def f7(a: Int)(using Int) = summon[Int] + a // OK
13+
}
1214

1315
package scala2main.unused.args:
1416
object happyBirthday {

tests/neg-custom-args/fatal-warnings/i15503f.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
/* This goes around the "trivial method" detection */
44
val default_int = 1
55

6-
def f1(a: Int) = a // OK
7-
def f2(a: Int) = 1 // OK
8-
def f3(a: Int)(using Int) = a // OK
9-
def f4(a: Int)(using Int) = default_int // OK
10-
def f6(a: Int)(using Int) = summon[Int] // OK
11-
def f7(a: Int)(using Int) = summon[Int] + a // OK
12-
def f8(a: Int)(using foo: Int) = a // error
13-
6+
object Xd {
7+
private def f1(a: Int) = a // OK
8+
private def f2(a: Int) = 1 // OK
9+
private def f3(a: Int)(using Int) = a // OK
10+
private def f4(a: Int)(using Int) = default_int // OK
11+
private def f6(a: Int)(using Int) = summon[Int] // OK
12+
private def f7(a: Int)(using Int) = summon[Int] + a // OK
13+
private def f8(a: Int)(using foo: Int) = a // error
14+
}
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
// scalac: -Wunused:params
22

33
/* This goes around the "trivial method" detection */
4-
val default_int = 1
4+
object Foo {
5+
val default_int = 1
56

6-
def f1(a: Int) = a // OK
7-
def f2(a: Int) = default_int // error
8-
def f3(a: Int)(using Int) = a // OK
9-
def f4(a: Int)(using Int) = default_int // error
10-
def f6(a: Int)(using Int) = summon[Int] // error
11-
def f7(a: Int)(using Int) = summon[Int] + a // OK
12-
13-
/* --- Trivial method check --- */
14-
def g1(x: Int) = 1 // OK
15-
def g2(x: Int) = ??? // OK
7+
private def f1(a: Int) = a // OK
8+
private def f2(a: Int) = default_int // error
9+
private def f3(a: Int)(using Int) = a // OK
10+
private def f4(a: Int)(using Int) = default_int // error
11+
private def f6(a: Int)(using Int) = summon[Int] // error
12+
private def f7(a: Int)(using Int) = summon[Int] + a // OK
13+
/* --- Trivial method check --- */
14+
private def g1(x: Int) = 1 // OK
15+
private def g2(x: Int) = ??? // OK
16+
}

tests/neg-custom-args/fatal-warnings/i15503h.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class A {
77
val b = 2 // OK
88

99
private def c = 2 // error
10-
def d(using x:Int): Int = b // error
10+
def d(using x:Int): Int = b // ok
1111
def e(x: Int) = 1 // OK
1212
def f =
1313
val x = 1 // error

tests/neg-custom-args/fatal-warnings/i15503i.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ class A {
1717
private def c2 = 2 // OK
1818
def c3 = c2
1919

20-
def d1(using x:Int): Int = default_int // error
20+
def d1(using x:Int): Int = default_int // ok
2121
def d2(using x:Int): Int = x // OK
2222

23-
def e1(x: Int) = default_int // error
23+
def e1(x: Int) = default_int // ok
2424
def e2(x: Int) = x // OK
2525
def f =
2626
val x = 1 // error
@@ -44,7 +44,11 @@ package foo.test.scala.annotation:
4444
val default_int = 12
4545

4646
def a1(a: Int) = a // OK
47-
def a2(a: Int) = default_int // error
47+
def a2(a: Int) = default_int // ok
48+
49+
private def a2_p(a: Int) = default_int // error
50+
def a2_p_used = a2_p(3)
51+
4852
def a3(@unused a: Int) = default_int //OK
4953

5054
def b1 =

0 commit comments

Comments
 (0)